Category Archives: C String

STRNSET() Function – C Program

In previous C Language Program post we had discussed about  Compare String and STRCAM Function and STRCAT Function and STRLEN Function and STRCPY Function and STRNCAT Function and STRNCPY Function and STRREV Function and STRUPR Function and STRLWR Function and STRSET Function.

STRNSET() Function – C Program

Write a C Program to sets some portion of the character of string to given character.

STRNSET() Function – The STRNSET() Function used to sets some portion of  character of string to given character in C Program.

The Syntax of STRNSET() Function :

strnset(str1,  ‘ * ‘, 5) –  First 5  character of string str1 replaced by character ‘ * ‘.

Example of STRNSET() Function C Program

The output of STRNSET() Function C Program is :

 

STRSET() Function – C Program

STRSET() Function – C Program

Write a C Program to sets all the character of string to given character.

STRSET() Function – The STRSET() Function used to sets all the character of string to given character in C Program.

The Syntax of STRSET() Function :

strset(str1,  ‘ * ‘) – All the character of string str1 replaced by character ‘ * ‘.

Example of STRSET() Function C Program

The output of STRSET() Function C Program is :

 

STRLWR() Function – C Program

STRLWR() Function – C Program

Write a C Program to converts given string to lower case latter.

STRLWR() Function – The STRLWR() Function used to converts given string to lowercase.

The Syntax of STRLWR() Function :

strlwr(str1)  – It converts the str1 contains to lowercase.

Example of STRLWR() Function C Program

The STRLWR() Function C Program output is :

 

STRUPR() Function – C Program

STRUPR() Function – C Program

Write a C Program to converts given string to upper case latter.

STRUPR() Function – The STRUPR() Function used to converts given string to uppercase.

The Syntax of STRUPR() Function :

strupr(str1)  – It converts the str1 contains to uppercase.

Example of STRUPR() Function C Program

The STRUPR() Function C Program output is :

 

STRREV() Function – C Program

STRREV() Function – C Program

Write a C Program to get string from user and display string in reverse order using STRREV() Function.

STRREV() Function – The STRREV() Function used to returns reverse order string of given string.

The Syntax of STRREV() Function :

strrev(str1) – display str1 contains to reverse order.

Example of STRREV() Function C Program

The output of STRREV() Function C Program is :

 

STRNCPY() Function – C Program

STRNCPY() Function – C Program

Write a  C Program to Copy string to another string using STRNCPY string function.

STRNCPY() Function – The STRNCPY() function used to copy some portion of contains second string into first string.

The Syntax of STRNCPY() Function :

strcpy (str1, str2, 5) – It copies first 5 character of str2 into str1.
strcpy(str2, str1, 3) – It copies first 3 character of str1 into str2.

Example of STRCPY() Function C Program

The output of STRNCPY() Function C Program is :

 

STRNCAT() Function – C Program

STRNCAT() Function – C Program

Write a C Program for concatenates two string using STRNCAT Function.

STRNCATE() Function : – The STRNCAT used to concatenate some portion of second string at the end of first string.

The Syntax of STRNCAT() Function :

strncat(str1, str2, 5) – The first 5 character of string str2 is concatenated at the end of string str1.
strncat(str2, str2, 2) – The first 2 character of string str1 is concatenated at the end of string str2.

Example of STRNCAT() Function C Program

The output of STRNCAT() Function C Program is :

 

STRCPY() Function – C Program

STRCPY() Function – C Program

Write a C Program to copy contains of one string to another string.

STRCPY() Function :- The STRCPY() function used to copy contains of one string to another string in c language.

The Syntax of STRCPY() Function :

strcpy (str1, str2) – It copies contains of str2 into str1.
strcpy(str2, str1) – It copies contains of str1 into str2.

Example of STRCPY() Function C Program

The output of STRCPY Function C Program is :

 

STRLEN() Function – C Program

STRLEN() Function – C Program

Write a C Program to calculate length of given string using STRLEN function.

STRLEN() Funcation : – The STRLEN() function used to get the length of given string, it count the number of character of given string and return integer value as result.

The Syntax of STRLEN() Function :

strlen(str1) – It returns the number of character of string str1.

Example of STRLEN() Function C Program

The output of strlen() string c program is :

 

Count Word and Character in String – C Program

Count Word and Character in String – C Program

Write a C Program to count number of word and character of given string.

The output of count word and character c program is :

 

Count Sub String From Given String – C Program

Count Sub String From Given String – C Program

Write a C Program to find how many times sub string from given main string.

The find sub string c program output is:

 

Compare String using STRCMP() – C Program

STRCMP() Function – C Program

Write a c program to compare two string using STRCMP() function.

STRCMP() Function – The STRCMP() Function used to compare two string, either it equal or not.

The Syntax of STRCMP() Function :

strcmp(str1, str2)  == 0 – both string str1 and str2 are equal.
strcmp(str1, str2)  !=0 – both string str1 and str2 are not equal.

Example of STRCMP() Function C Program

The String Compare C Program output is :