Read a string from user using gets() function. Now travel the whole string and check it is an alphabet or Not. If it is an alphabet then check it position. If it is first character of the string and it is a small character [ASCII between 97 - 122], then convert it into upper case letter and other all charcter convert into lower case letter. Now check the others character of the string, if those characters are alphabets and capital letters [ASCII between 65 - 90], then convert it into small letter by adding 32 with it. Now print the string using puts().
int main() { char str[30],i; //READ A STRING printf("Enter A String: "); gets(str); for(i=0;str[i]!='\0';i++) { if((str[i]>=65 && str[i]<=90) ||(str[i]>=97 && str[i]<=122)) { if(i==0) { if(str[i]>=97 && str[i]<=122) { str[i]=str[i]-32; } } else { if(str[i]>=65 && str[i]<=90) { str[i]=str[i]+32; } } } } //PRINT THE OUTPUT printf("Result : "); puts(str); return 0; }
Enter A String: i am An Indian
Result : I am an indian