Hi.I have written this code which capitalizes 1st character of each word in the string.All other letters of the word has to be in small letter.But i am not getting desired output.Plz tell me where i am going wrong..
#include<stdio.h>
int main(void)
{
char string[]="hI i aM sOujanYa";
char string2[20]="";
char *ptr;
int i;
ptr=&string[0];
string2[0]=*ptr;
for(i=0;*ptr!='\0';*ptr++,i++)
{
if(*ptr>='a' && *ptr<='z')
*ptr=*ptr-32;
string2[i]=*ptr;
*ptr++;
i++;
while(*ptr!=' '&& *ptr!='\0')
{
if(*ptr>='A'&& *ptr<='Z')
*ptr=*ptr+32;
string2[i]=*ptr;
*ptr++;
i++;
}
}
string2[i]='\0';
puts(string2);
}