Sunday, March 17, 2013

Changing String To Sentence Case

#include<iostream>
using namespace std;
void sencase(char [][30],int);//function to change to sentence 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)//input of string
    {
        cin.getline(a[i],30);
    }
    cout<<"\n\nThe strings are:\n\n";
    for(i=0;i<=m;++i)//display
    {
        cout<<a[i]<<"\n";
    }
    sencase(a,m);//calling function
    cout<<"The result is: \n\n";
    for(i=0;i<=m;++i)
    {
        cout<<a[i]<<"\n";
    }
    return 0;
}
void sencase(char a[][30],int m)//definition of the user-defined function
{
    int i,j;
    for(i=0;i<=m;++i)
    {
        a[i][0]=toupper(a[i][0]);
        for(j=0;a[i][j]!='\0';++j)
        {
            if(a[i][j]==' ')
            a[i][j+1]=toupper(a[i][j+1]);
        }
    }
}

0 comments:

Post a Comment