%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
String predefined functions in C programming
1. Strings in C Programming
By Asst. Prof. Sonali Gholve
String
predefined
functions
Strlen()
Strrev()
Strcat()Strcpy()
Strcmp()
2. Predefined string functions
• C Programming language provides a set of
predefined string functions called string
handling functions to work with string values.
• <string.h>
– strlen()
– strrev()
– strcat()
– strcpy()
– strcmp()
3. Strlen()
This function is used to calculate length of string.
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=“India”;
printf(“Length of string=%d”, strlen(a));
return 0;
}
0 1 2 3 4 5 6 7
I n d i a 0
Output:
Length of string=5
4. Strrev()
This function is used to reverse the given string .
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=“India”;
Printf(“string before reversing=%s”,a);
printf(“Reverse of given string=%s”, strrev(a));
return 0;
}
0 1 2 3 4 5 6 7
I n d i a 0
0 1 2 3 4 5 6 7
a i d n i 0
Output:
String before reversing=India
Reverse of given string=aidni
5. Strcat()
This function is used to concatenates two given strings.
It concatenates source string at the end of target string.
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=“Hello”, b[20]=“Pune”;
printf(“string first before concatenate=%s”,a);
strcat(a,b);
printf(“String after concatenation=%s”, a);
return 0;
}
0 1 2 3 4 5 6
H e l l o 0
0 1 2 3 4 5 6 7
P u n e 0
Output:
String first before concatenate =Hello
String after Concatenation=HelloPune
0 1 2 3 4 5 6 7 8 9 10
H e l l o P u n e 0
6. Strcpy()
This function is used to copy one string into other
character array .
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=“India”, b[20];
strcpy(b,a);
printf(“Contents of string second=%s”, b);
return 0;
}
0 1 2 3 4 5 6 7
I n d i a 0
0 1 2 3 4 5 6 7
I n d i a 0
Output:
Contents of string second=India
0 1 2 3 4 5 6 7
7. Strcmp()
This function is used to compare two strings.
0=> If strings are same
+ve=>ASCII of first character is greater
-ve=> ASCII of first unmatched character is less
#include<stdio.h>
#include<string.h>
int main()
{
char a[20]=“ANT”, b[20]=“BALL”;
char c[10]=“ANT”;
int result;
result=strcmp(a,b);
printf(“strcmp(a,b)=%dn”, result);
result=strcmp(b,c);
printf(“strcmp(b,c)=%dn”, result);
return 0;
}
0 1 2 3 4 5 6 7
A N T 0
Output:
Strcmp(a,b)=-1
Strcmp(b,c)=0
0 1 2 3 4 5 6 7
B A L L 0
0 1 2 3 4 5 6 7
A N T 0