String
String
It is declared as
char name[size];
The last character of the string is ‘\0’.
Like array we can retrieve any character from
the string.
The header file string.h includes many
readymade functions related to the string.
Some of them are as listed below.
1. strlen(string name);
This function gives the length of string which is
passed as an argument to the strlen() function.
e.g. if the string is I am a boy
the strlen function gives result 10.
2. strrev(string name);
This function reverses the given string
e.g. if the string is abcd
the strrev function gives result dcba.
3. strcat(string1,string2);
This function concatenates the string2 at the
end of the string1
4. strcpy(string1,string2);
This function copies the string2 into the string1
5. strcmp(string1,string2);
This function compares string1 with string2
and gives 0 result if both the strings are equal.
Gives positive result if string1 is greater than
string2.
Gives negative result if string1 is smaller than
string2.