The document discusses strings in C programming. It defines strings as arrays of characters terminated by a null character. It explains that string handling functions are declared in the string.h header file and are used to perform operations on strings like getting the length, concatenating, comparing, and manipulating case. Several functions are described like strlen(), strcpy(), strcat(), strcmp(), strrev(), strlwr(), strupr(). Examples are given showing how to use these functions to work with strings.
2. The string is actually a one-dimensional array of characters
which is terminated by a null character '0'.
All the string handling functions are prototyped in: string.h
header file. So while using any string related function, don't
forget to include string.h.
String constants have double quote marks around them.
String constants can be assigned to a char array either with
no size specified, or the size can also be specified, but don't
forget to leave a space for the null character.
3. Strings are often needed to be manipulated by the programmer
according to the need of a problem. Hence, C provides a
variety of string handling functions.
String handling functions refers to a group of functions
implementing various operations on strings.
Some of the operations performed by the string handling
functions includes:
› Length (number of characters in the string).
› Concatenation (adding two are more strings)
› Comparing two strings.
› Substring (Extract substring from a given string)
› Copy(copies one string over another)
4. The various string handling functions supported by C are as
follows:
strlen()
It is used to find the length of the string.
syntax:
strlen(string)
strcpy()
It is used to copy one string to another.
syntax:
strcpy(string1,string2)
strcat()
It is used to combine two strings.
syntax:
strcat(string1,string2)
5. strcmp()
It is used to compare two strings.
syntax:
strcmp(string1,string2)
Returns 0 if two strings are equal.
Return value <0 if s1 is less than s2.
Return value >0 if s1 is greater than s2.
strrev()
It used to reverse a string.
syntax:
strrev(string)
strlwr(), strupr()
It used to change the case of a string.
syntax:
strlwr(string)
strupr(string)
6. strncpy()
It used to copy ‘n’ characters of one string to another.
strstr()
It is used to determine the first occurrence of a
given string in another string.
strncat()
It appends source string to destination string up to
specified length.
strspn()
It is used to find up to what length two strings are
identical.
7. strncmp()
It is used to compare ‘n’ character of two strings.
strcmpi()
It is used to compare two strings without regarding the case.
strnicmp()
It is used to compare first ‘n’ characters of two strings
without regarding the case.
strchr()
It is used to determine the first occurrence of a given
character in a string.
strrchr()
It is used to determine the last occurrence of a given
character in a string.