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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.