Monday, January 7, 2013

Program for Case Conversion



C/C++ Program for Case Conversion



#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
int main(){
clrscr();
int i,j,n,k;
char *s;

      cout<<" \" This program will convert upper case to lower or vice virsa. \""<<endl<<endl;

      cout<<"What is the string ?. Give a String/Sentence. :"<<endl;
      gets(s);

      k=strlen(s);
      cout<<endl<<"The string that you have given is :"<<endl;
      cout<<s;

      cout<<endl<<"After case conversion it is :"<<endl;

      for(i=0;i<=k;i++) {
      n=int(s[i]);

      if(n==32) {
      s[i]=char(n);
      cout<<s[i];
      }

      else if((n>=48) && (n<=57)){
      s[i]=char(n);
      cout<<s[i];
      }

      else if((n>=97) && (n<=122)) {
      n=n-32;
      s[i]=char(n);
      cout<<s[i];
      }

      else if((n>=65) && (n<=90)) {
      n=n+32;
      s[i]=char(n);
      cout<<s[i];
      }
      }

getch();
}

No comments:

Post a Comment