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<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
cout<<”Input your
name”;
strcpy(a, “pramod”);
strcat( a, “dwivedi”);
cout<< a;
getch();
}
Output:
Input your name
Pramoddwivedi
2.strlen()
Computes string’s
length.
Syntax :
Variable name= strlen(string);
Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a1[20],
a2[20];
int len1,len2;
cout<<”Input
Value”;
cin>>a1;
cin>>a2;
len1=strlen(a1);
len2=strlen(a2);
cout<<len1;
cout<<len2;
getch();
}
Output:
Input Value
Pramod
Dwivedi
6 7
3.strcpy()
Copies a string to
another.
Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char str2[]={dwivedi};
char str1[20];
strcpy(str1, str2);
cout<<str1;
cout str2;
getch();
}
Output:
Dwivedi
Dwivedi
4. strcmp()
Compare two String.
Syntax:
Variable name=
strcmp(str1, str2);
Program
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int s;
char a1[20];
char a2[30];
cout<<”input
String”;
cin>>a1;
cin>>a2;
s=strcmp(a1,a2);
getch();
}
Output:
Input String
Pramod
Ram
9
5.strlwr()
Convert string to
lowercase.
Syntax:
Strlwr(string name);
Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
cout<<“Input
String”;
cin>>a;
strlwr(a);
cout<<a;
getch();
}
Output:
Input String
PRAMOD
pramod
6.strupr()
Converts into
uppercase.
Syntax:
Strupr(string name);
Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
cout<<“Input String”;
cin>>a;
strupr(a);
cout<<a;
getch();
}
Output:
Input String
pramod
PRAMOD
7. strrev()
Converts string to
reverse .
Syntax:
Strrev(string name);
Program:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
cout<<“Input
String”;
cin>>a;
strrev(a);
cout<<a;
getch();
}
Output:
Pramod
domap
No comments:
Post a Comment