You are on page 1of 24

String Functions

by

Ashish Jain
• String Functions are used to perform string
related operations.
• These functions are defined in a header file
called <string.h>
Important String Functions
1. strlen()
2. strupr()
3. strlwr()
4. strrev()
5. strcpy()
6. strcat()
7. strcmp()
strlen() function
• This function is used to find out length of a
string.
Example
#include<stdio.h>
#include<string.h>
void main()
{
char x[10]=“Welcome”;
int n;
n=strlen(x);
printf(“%d” , n);
}
Ouput
7
strupr() function
• This function is used to convert a string into
upper case.
Example
#include<stdio.h>
#include<string.h>
void main()
{
char x[10]=“Welcome”;
strupr(x);
printf(“%s” , x);
}
Output
WELCOME
strlwr() function
• This function is used to convert a string into
lower case.
Example
#include<stdio.h>
#include<string.h>
void main()
{
char x[10]=“WELCOME”;
strlwr(x);
printf(“%s” , x);
}
Output
welcome
strrev() function
• This function is used to reverse a string.
Example
#include<stdio.h>
#include<string.h>
void main()
{
char x[10]=“WELCOME”;
strrev(x);
printf(“%s” , x);
}
Output
• EMOCLEW
strcpy() function
• This function is used to copy one string into
another string.
Example
#include<stdio.h>
#include<string.h>
void main()
{
char x[10]=“WELCOME”;
char y[10];
strcpy(y, x);
printf(“%s” , y);
}
Output

WELCOME
strcat() function
• This function is used to concatenate
( append ) one string after another string.
Example
#include<stdio.h>
#include<string.h>
void main()
{
char x[15]=“Good”;
char y[10]=“Morning”;
strcat(x, y);
printf(“%s” , x);
}
Output
GoodMorning
strcmp() function
• This function is used to compare two
strings. It return 0 if the strings are same
otherwise it return non zero value.
Example
void main()
{
char x[10]=“WELCOME”;
char y[10]=“WELCOME”;
int n;
n=strcmp(x, y);
if(n = = 0 )
{
printf(“Strings are same”);
}
else
{
printf(“Strings are different”)
}
}
Output
Strings are same

You might also like