String Library Function In C Language
In this header file
string related header file are include and function definition are store in it, in
this character group are include and there are different type function are
available on it. C Support a large number
of string handling function in the standard library String.h.
Example:
Strcat(), strcmp(),
strrev(), strupr(), strlen(), strlwr(), strcpy().
1. Strcat()
Concatenates(join) two
strings
Synatx:
Strcat (str1,str2);
Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
printf(“Input your
name”);
strcpy(a, “pramod”);
strcat( a, “dwivedi”);
printf( “ ”, a);
getch();
}
Output:
Input your name
Pramoddwivedi
2.strlen()
Computes string’s
length.
Syntax :
Variable name=
strlen(string);
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a1[20],
a2[20];
int len1,len2;
printf(“Input Value”);
scanf(“%c”, &a1);
scanf(“%c”, &a2);
len1=strlen(a1);
len2=strlen(a2);
printf(“ “, len1);
printf(“ ”, len2);
getch();
}
Output:
Input Value
Pramod
Dwivedi
6 7
3.strcpy()
Copies a string to
another.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str2[]={dwivedi};
char str1[20];
strcpy(str1, str2);
printf(“ “, str1);
printf(“ ”, str2);
getch();
}
Output:
Dwivedi
Dwivedi
4. strcmp()
Compare two String.
Syntax:
Variable name=
strcmp(str1, str2);
Program
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int s;
char a1[20];
char a2[30];
printf(“input String”);
scanf(“%c”, &a1);
scanf(“ %c”, &a2);
s=strcmp(a1,a2);
getch();
}
Output:
Input String
Pramod
Ram
9
5.strlwr()
Convert string to
lowercase.
Syntax:
Strlwr(string name);
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
printf(“Input String”);
scanf(“%c”, &a);
strlwr(a);
printf(a);
getch();
}
Output:
Input String
PRAMOD
pramod
6.strupr()
Converts into
uppercase.
Syntax:
Strupr(string name);
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
printf(“Input String”);
scanf(“%c”, &a);
strupr(a);
printf(a);
getch();
}
Output:
Input String
pramod
PRAMOD
7. strrev()
Converts string to
reverse .
Syntax:
Strrev(string name);
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
printf(“Input String”);
scanf(“%c”, &a);
strrev(a);
printf(a);
getch();
}
Output:
Pramod
domap
No comments:
Post a Comment