Sunday, March 17, 2013

Changing Case Of A String

#include<iostream>
using namespace std;
void chncase(char [][30],int);//function for changing case
int main()
{
    int m,i;
    char a[15][30];
    cout<<"Enter number of strings: ";
    cin>>m;
    cout<<"\nEnter the strings :\n\n";
    for(i=0;i<=m;++i)
    {
        cin.getline(a[i],30);
    }
    cout<<"\n\nThe strings are:\n\n";
    for(i=0;i<=m;++i)
    {
        cout<<a[i]<<"\n";
    }
    chncase(a,m);//calling function
    cout<<"\n\nThe changed strings are: \n\n";
    for(i=0;i<=m;++i)
    {
        cout<<a[i]<<"\n";
    }
    return 0;
}
void chncase(char a[][30],int m)//function definition
{
    int i,j;
    for(i=0;i<=m;++i)
    {
        j=0;
        while(a[i][j]!='\0')
        {
            if(islower(a[i][j]))
            a[i][j]=toupper(a[i][j]);
            else
            a[i][j]=tolower(a[i][j]);
            ++j;
        }
    }
}

0 comments:

Post a Comment