What is a string?
A string is a group of characters ended with null character. It is also known as array
of characters.
Declaration
char name_of_the_string;
where name of the string must be valid identifier & size must be an integer constant
Most useful functions available inside string.h header file
strcpy()
This function copies one string into another string.
Format: strcpy(s1,s2)
where s1 is a string variable and s2 is a string variable or string constant.
e.g. strcpy("Hello",s1);
will copy Hello to string variable s1.
strlen()
It counts the number of characters including null in the given string.
e.g. cout<<strlen("c++");
Output: 4
strcmp()
Format: strcmp(s1,s2);
This function will return 0 if two strings are equal, -1 if 1st string is smaller than 2nd and 1 if 1st string is greater than 2nd
This function is case sensitive & compares two strings by ASCII value of the characters.
strrev()
It prints given string into its reverse order
e.g. cout<<strrev("abc");
Output: cba
strcat()
This function add two strings.
Format: strcat(s1,s2)
e.g. cout<<strcat("abc","xyz");
Output:abcxyz
strupr()
It converts given string in uppercase.
Format: strupr(s1)
where s1 can be a string variable or a string constant.
strlwr()
It converts given string in lowercase. Format is same as that of strupr().
If you liked this post please rate it and if not then tell me why, your feedback will help me in boosting up
my confidence so that I can write more useful post in the future.