Categories: C LanguageLearn C++

Pre-defined string function example C Programming language

Pre-defined string function in C Programming language

In this tutorial, we will discuss the pre-defined string function in the C Programming language.


The c programming language has inbuilt string functions which are declared in string.h header file. This functions can be used in many string operations in C language.

1. strlen() – The String function can be used to calculate the length of String

Syntex

strlen(string_name) ;
Example

Output

20

2. strupr() – this function converts the given string into uppercase

Syntex

strupr(string_name) ;
Example

Output

MY NAME IS MR KANNAN

3. strlwr () -this function converts the given string into lowercase

Syntex

strlwr(string_name) ;
Example

3. strset() – this function sets all characters in string to ch

Syntex

strset(string_name,'ch') ;

 

Example

Output

**************

4. strnset()-this function helps to set the first given numbers of  character in string to ch

Syntex

strnset(string_name,'ch',count) ;

 

Example

Output

******s string function

5. strrev()- This function reverses all character in given String

Syntex

strrev(string_name) ;

 

 

Example
Output
noitcnuf gnirts si siht
6. strspn()-this function gives the number of character in the initial segment of first_string_name, which has the same characters from second_string_name

Syntex

strspn(first_string_name,second_string_name) ;
Example

Output
8

7. strcmp()-this function compares two strings and gives an integer value

when string 1 was  equal to string 2, return value 0
when string 1 was less than string 2, return value is a negative integer;
when string 1 was greater than string 2, the return value is a negative integer;

Syntex

strcmp(first_string_name,second_string_name) ;

Output
-1

8. stricmp()-this function compares two strings and the given integer value but not it is not case sensitive

when string 1 was  equal to string 2, returns value is 0
when string 1 was less than string 2, returns value is a negative integer;
when string 1 was greater than string 2, returns value is a negative integer;

Syntex

stricmp(first_string_name,second_string_name) ;

Output
0

9. strcpy()-this function copies the content of one string into another string 


Syntex

strcpy(first_string_name,second_string_name) ;

Output

this is function

10. strncpy

this function copies the given number of character of one string to another

Syntex

strcmp(first_string_name,second_string_name,count) ;

 

Output

learn

11. strstr()-This function returns the pointer to first occurrence of first_string in second_string

Syntex

strstr(first_string_name,second_string_name) ;

Output

c language

12. strcat()- concatenates second_string at the end of the first_string


Syntex

strcat(first_string_name,second_string_name) ;

Output

learning c language

13. strncat()- concatenates given number of character of second_string at the end of the first_string

Syntex

strstr(first_string_name,second_string_name,count) ;

Output

learning java and c

14.strchr-

The strrchr() function is used to returns a pointer to the first occurance of the given string

Syntax

char* strrchr (const char *str,int c)

15. strrchr()-

The strrchr() function is used to returns a pointer to the last occurance of the given string

Syntax

char* strrchr (char* str,int ch)

Output
language

16. strdup()-

The strdup() function is used to duplicate the given string

Stntax

char*strdup(const char*s)

Output
learning c language

17. strrev()-

The strrev() function is used to reverse the given string

Syntax

char*strrev(char *str)

 

Example

 

Suggested for you

Function in C language

String function in C language

String function in Python language

Arithmetic function in Python language

 

Karmehavannan

Recent Posts

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.