Conversion of Strings into Upper and Lower Case

String: " A combination of Characters is called String".


Functions For Strings:
C++ supports wide variety of functions having different properties to deal with Strings.Some of them are given below.

Note: To use these functions don't forget to include library   ==>   #include<cstring> or  #include<string.h>

  1. strcpy( str1,str2 );                ==>   Copies string 2 to string 1.
  2. strlen(str1);                          ==>   Gives the length of string 1.
  3. strcmp(str1,str2);                 ==>   Do comparison. if equal result = 0 , if str2 is greater than str1                                                               result > 0  ,  if str2 is smaller than str1 then result < 0
  4. strcat(str1,str2);                   ==>   Concatenates string 1 and string 2.
If you don't about Strings ... read this article
Algorithm:   Get string and copy it into another string and then convert it into upper and lower case by using this command 

strupr(string_name)   ==> for upper case
strlwr(string_name)   ==> for lower case


Program code:

#include<iostream>#include<conio.h>#include<string.h>using namespace std;

int main()
{
   char istring[30] , ostring[30] , redo ;
 
   cout<<"**************************************************"<<endl;
   cout<<"  Conversion of String into Upper and Lower case  "<<endl<<endl;
   cout<<"**************************************************"<<endl<<endl;
 
 
 
   do
   {
 
            cout<<"Enter String"<<endl<<endl;
            cin>>istring;
            cout<<endl<<endl;
           
            strcpy(ostring,istring);
 
            cout<<"String in lower Case  :"<<endl<<endl;
            cout<<strlwr(ostring);
            cout<<endl<<endl;
 
            cout<<"String in Upper Case  :"<<endl<<endl;
            cout<<strupr(ostring);
            cout<<endl<<endl;
 
 
       cout<<"**************************************************"<<endl;
     
       cout<<"  For more conversion enter y or Y  =  ";
       cin>>redo;
       cout<<endl<<endl;
   
   }while(redo == 'y' || redo == 'Y');
   getch();
}


Output: After compile and run the output will be like this 

Click on pic to enlarge it.

Hope that you will find this helpful.

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.