C++ Program for All the String Operations using strlen, strcpy, strcat, strcmp, strupr, strlwr, strrev functions

AIM:
To write a C++ Program for All the String Operations like String Length(strlen), String Copy(strcpy), Strings Concatenation(strcat), String Comparision(strcmp), Changing the String into Upper Case(strupr) and Lower Case(strlwr), String Reverse(strrev).


SOURCE CODE:
#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();
}
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: