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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

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,…

1 year 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…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

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

1 year 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…

1 year ago

This website uses cookies.