"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, January 7, 2010

A program that reads a string & a character . Each occurrence of the given character (regardless of its case) is converted to opposite case.

#include(iostream.h)
#include(conio.h)
#include(string.h)


void main()
{
char str[30], ch, ch1;


cout<<"\n Enter a String:";
cin.getline(str,30);


cout<<"\n Enter a character :";
cin>>ch;


for(int i =0; str[i]!='\0'; ++i)
{
if(toupper(ch) = = toupper(str[i]))
  {
    if(str[i]>='A' && str[i]<='Z')
         str[i] = str[i] + 32;
     else
         str[i] = str[i] - 32;
}
}


cout<<"\n The Converted String is  "<< str;
getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.