In C language, an array of characters is known as a string. Consider the following example to declare a string :
char st[50]
This statement declares a strings array with 50 characters. The control character '\0' which represents a null character is placed automatically at the end of any string used.
char name[5] = {'A', 'y', 'a', 'N', '\0'};
There are four important string handling functions in C Language.
strlen() function is used to find the length of a character string.
|
This will return length of the string 9 which is assigned to an integer variable n.
Note : That the null character '\0' available at the end of a string is not counted.
strcpy() function is used to copy a character variable.
|
This will assign the string "BANGALORE" to the character variable city.
Note : That character value like city = "BANGALORE"; cannot be assign in C language.
strcat() function is used to join character stings. When two character strings are joined, it is referred as concatenation of strings.
|
This will join the two strings and store the result in city as "BERHAMPORE742103".
Note : That the resultant string is always stored in the left side string variables.
strcmp() function is used to compare two character strings.
|
This will return an integer value - 10 which is the difference in the ASCII values of the first mismatching letters 'B' and 'N'.
Note : That the integer value obtained as the difference may be assigned to an integer variable as follows :
int n;
n = strcmp(city,town);
<string.h> is header in the C standard library for the C language which help us for handling string functions and memory functions.
|
Note : gets() use for read strings (Data input) and puts() use for write strings (Data output).
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.