String Handling Functions
String Handling Functions
• Most, if not all, of the time string manipulation can be done manually but, this makes programming
complex and large.
• To solve this, C supports a large number of string handling functions in the standard library
"string.h".
• Following are the popular String handling functions available in string.h header file
strcat()
strcmp()
strcpy()
strlen()
• length of the resulting string is sum of the length of source and destination string
• General Syntax
strcat(dest, src);
• In this, the dest should be a character array variable and src can either be a string constant or a
char array.
#include <stdio.h>
#include <string.h>
int main(){
char str1[20]="Programming";
char str2[20]="Logic";
strcat(str1,str2);
return 0;
Output : ProgrammingLogic
String Comparison
• General Syntax
strcmp(string1, string2);
• comparison starts with the first character in each string and continues with subsequent
characters until the corresponding characters differ or until the end of the strings is reached.
String Comparison
#include <stdio.h>
#include <string.h>
int main(){
if (strcmp(str1,str2) < 0)
else
return 0;
}
String Copy
• Syntax
strcpy(dest, src);
• Example
char course[40];
strcpy(course, “C Programming”);
Programming”.
String Length
• Syntax
strlen(string);
#include <stdio.h>
#include <string.h>
int main(){
int length;
length = strlen(str1);