String Functions in C
Typing Speed: 25

Ismail
Ismailpk456@gmail.com
Ismail Ismu
Ismail Ismu
in.linkedin.com/in/profilena
me
8086303494
String Function
The standard library for C string functions
is string.h. This header file defines tons
of useful string manipulation functions
including
String Functions

 strcmp
 strcat
 strcpy
 strlen
strcmp
• Strcmp() in C programming language is used
to compare two strings. If both the strings are
equal then it gives the result as zero but if not
then it gives the numeric difference between
the first non matching characters in the
strings.
strcat
• The strcat() function is used for string
concatenation in C programming language. It
means it joins the two strings together
strcpy
• strcpy function copies a string from a source
location to a destination location and provides
a null character to terminate the string.
strlen
The strlen( ) function is used to calculate the
length of the string. It means that it counts the
total number of characters present in the
string which includes alphabets, numbers, and
all special characters including blank spaces.
Strcmp
Syntax
int strcmp ( const char * str1, const char * str2 );

Example
int main()
{
char str1[30],str2[30];
printf("Enter first string: ");
scanf("%s",&str1);
printf("Enter second string: ");
scanf("%s",&str2);
if(strcmp(str1,str2)==0)
printf("Both strings are equal");
else printf("Strings are unequal");
return 0;
}
Strcat
Syntax
strcat(first_string,second_string);
Example
int main()
{
char str1[30]="www.cprogramming";
char str2[15]="expert.com";
printf("nn string 1 : %stt string 2 : %snn",str1,str2);
printf("nn strcat(str1,str2) : %snn", strcat(str1,str2));
getch();
Strcpy
Syntax
strcpy(destination,source);

Example
int main()
{
char a[10],b[10];
printf("Enter string: ");
scanf("%s",&a);
strcpy(b,a);
printf("Copied string: ");
printf("%s",b);
return 0;
}
Strlen
Syntax
temp_variable = strlen(string_name);

Example
int main()
{
char a[20];
printf("Enter string: ");
scanf("%s",&a);
printf("Length of string =%d n",strlen(a));
}
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.

Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
THE END

String functions in C