written 6.0 years ago by | • modified 6.0 years ago |
Subject : Structured Programming Approach
Title : Arrays, String, Structures and Union
Marks : 10M
written 6.0 years ago by | • modified 6.0 years ago |
Subject : Structured Programming Approach
Title : Arrays, String, Structures and Union
Marks : 10M
written 6.0 years ago by |
C library supports a large number of string-handling functions that can be used to carry out many of the string manipulation activities. Following are the most commonly used string-
if(strcmp(a,b)>0)
printf("%s string is greater",a);
else
printf("%s string is greater",b);
getch();
The strcat function joins two strings together. It takes the following form
strcat( string1,string2);
Eg: strcat(part1, “GOOD”);
strcat(strcat(string1,string2),string3);
Here three strings are concatenated and the result is stored in string1.
strcmp( ) Function
It is used to compare two strings identified by the arguments and has a value 0 if they are equal. It takes the form:
strcmp(string1,string2);
Eg: 1) strcmp(name1,name2);
2) strcmp(name1,”john”;
3) strcmp(“ram”, “rom”);
strcpy( ) Function
This function works almost like a string assignment operator. It takes the form
strcpy(string1,string2);
This assigns the content of string2 to string1.
Eg: 1) strcpy(city, “DELHI”);
2) strcpy(city1,city2);
strlen( ) Function This function counts and returns the number of characters in a string.
n = strlen(string);