Operation On String
Write a program to perform following operation on string:
1. Find out Length of string
2. Copy.
3. Combined of two String.
4. A String breaks into two parts
5. Case Conversion
6. Comparison.
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char s1[20],s2[20],i;
clrscr();
cout<<"Enter the string to find the length:";
cin>>s1;
cout<<"\nLength of the string is..."<<strlen(s1);
strcpy(s2,s1);
cout<<"\n\nCopied string is..."<<s2;
cout<<"\n\nEnter 2 strings to be concatenated:";
cin>>s1>>s2;
strcat(s1,s2);
cout<<"\nConcatenated string is..."<<s1<<endl;
cout<<endl<<"\nEnter 2 strings to be compared:";
cin>>s1>>s2;
i=strcmp(s1,s2);
if(i==0)
cout<<"\nBoth strings are equal\n";
else if(i<0)
cout<<s1<<" is less than "<<s2<<endl;
else
cout<<s1<<" is greater than "<<s2;
cout<<"\n\nEnter the string to change into lower case:";
cin>>s1;
cout<<"\nLower case of the given string is..."<<strlwr(s1);
cout<<"\n\nEnter the string to change into upper case:";
cin>>s1;
cout<<"\nUpper case of the given string is..."<<strupr(s1);
cout<<"\n\nEnter the string to be reversed:";
cin>>s1;
cout<<"\nThe reversed string is..."<<strrev(s1);
getch();
}
OUTPUT:
Comments
Post a Comment