2. What is a string?
String is any group of characters. In
programming string is “Array” of characters.
For example:
Char name[5] = ”Sunny”
Location 0x9 0xA 0xB 0xC 0xD 0xE
Values S u n n y n
Char name[5]
3. String.h
This is a header file can be used in c/c++
programming.
This file consist of many string handling
functions. Some of them are
− strlen()
− Strcmp()
− Strcmpi()
− Strcpy()
− strcat()
4. strlen()
“Strlen” stands for “string length”. This function is
used when we need to find length of any string.
For example: we have a char string, name[10]
and stored value is “Sunny”.
Size of the array is 10. Means we can store
maximum 10 bytes of data. Or 10 characters. But
the stored value is Sunny, consist of 5 characters
only. Lets count with the help of strlen().
5. Strcmp()
This fuction is used to compare to strings.
Strcmp() use ASCII standard to compare two
strings.
For example: we have two strings
Char n[10]=”poonam”
Char m[10]=”sunny”
Strcmp() has two parameters.
strcmp(destination_string,source_string)
We will write: strcmp(n,m);
6. strcmpi()
This function also uses for comparing two
strings.
But the diffrence is, for this function both
“poonam” and “PoOnaM” is same. This will return
0 when we compare them
But in case of strcmp() it will not be the same.
Strcmpi() has two parameters.
strcmpi(destination_string,source_string)
We will write: strcmpi(n,m);
7. strcpy()
This function is used to copy one string to
another string.
For example we have two character arrays.
m[10]=”Sunny”, n[10];
Strcpy() has also two parameters.
strcppy(destination_string,source_string)
We will write: strcpy(n,m);
We will get: m[10]=”Sunny”, n[10]=”Sunny”
8. strcat()
This function is used to concate two strings each
other.
Strcat() has two parameters.
strcmp(destination_string,source_string)
We will write: strcat(n,m);
For if we have n[11]=”sunny ” and m[10]=”Leone”
After concate we will get “Sunny Leone”.