1.String is a collection of character.
2.C does not support string data type therefore char data type is used to make string .
3.String in c is stored in single dimension character array.
4.There are many predefined string function in C library.
5.All the string functions are predefined in string.h header file.
String Function
Function name | Description |
---|---|
strlen(s); | It is used to get the length of string. |
strcpy(s1,s2); | It is used to copy the string here string s2 is copied into string s1. |
strcat(s1,s2); | It is used to add two string here string s2 concatenates at the end of string s1. |
strcmp(s1,s2); |
1.It is used to compare two string. 2.This function returns 0 if string s1 and string s2 are same. 3.This function returns negative value if s1<s2. 4.This function returns positive value if s1 >s2 . |
strrev(s); | It is used to reverse the string. |
strupr(s); | It is used to convert all the character into upper alphabet. |
strlwr(s); | It is used to convert all the character into lower alphabet. |
strcmpi(s1,s2); | It is also used to compare two string but it ignores the case sensitivity means 'a' and 'A' are treated as same. |
strlen()
It is used to find the length of the Specified string.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char name[200]="Easy"; printf("%d",strlen(name)); return 0; } ### Output ### 4 //because there is 4 character in Easy
It is used to copy one string into another.
It has two parameters.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char name1[200]="Radha"; char name2[200]="Rani"; strcpy(name1,name2); printf("%s",name1); return 0; } ### Output ### Rani
It is used to compare one string with another.
It returns zero if both strings are same otherwise returns non-zero.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char s1[200]="Easy"; char s2[200]="Easy"; if(strcmp(s1,s2)==0) { printf("string s1 and string s2 are same."); } else { printf("string s1 and string s2 are not same."); } return 0; } ### Output ### string s1 and string s2 are same
It is used to concatenate one string with another.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char s1[200]="Easy"; char s2[200]=" Softwares"; printf("%s",strcat(s1,s2)); return 0; } ### Output ### Easy Softwares
It is used to reverse the string .
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char s[200]="ABCD"; printf("%s",strrev(s)); return 0; } ### Output ### DCBA
It is used to convert only lowercase alphabet into uppercase.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char s[200]="Easy"; printf("%s",strupr(s)); return 0; } ### Output ### EASY
It is used to convert only uppercase alphabet into lowercase.
#include<stdio.h> #include<conio.h> #include<string.h> int main() { char s[200]="Easy"; printf("%s",strlwr(s)); return 0; } ### Output ### easy
Here
I am requesting if you found this post was helpful for you then let me
know by your comment in below comment box and share it with your friend.
Also you can contact me on Instagram @rajusunagar_
If
you have not subscribed my website then please subscribe my website.
Try to learn something new and teach something new to other.
Thank you!!.......
0 Comments