Computer Scientists are Pretty Pessimistic

Thursday 1 October 2015

WAP to input a multi word string and produce a string in which first letter of each word is capitalized.

CODE ::

#include <stdio.h>
#include <string.h>
int main ()
{
    char c[100];
    int i;
    printf("Enter string: ");
    gets(c);
    for(i=0;i<c[i];i++)
    {
        if(c[0]>='a'&&c[0]<='z')
            c[0]=c[0]-'a'+'A';

        if(c[i]==' '||c[i]=='.'||c[i]==','||c[i]=='?'||c[i]=='!'||c[i]==';'||c[i]==':')
        {
            if(c[i+1]>='a'&&c[i+1]<='z')
                c[i+1]=c[i+1]-'a'+'A';
        }
        printf("%c",c[i]);
    }
    return 0;
}

No comments:

Post a Comment