Reputation: 5
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[20],temp;
printf("enter the string\n");
gets(str);
for(int i = 0; i < strlen(str); i++)
{
if(tolower(str[i])){
str[i] = toupper(str[i]);
}else{
printf("enterred\n");
str[i] = tolower(str[i]);
}
}
printf("%s\n", str);
return 0;
}
I am not able to understand why is this not working the lowercase is turned to uppercase but the wise versa is not happening. it is a very simple program but still, I am not able to understand.
Upvotes: 0
Views: 52
Reputation: 242
Try this...
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[20],temp;
printf("enter the string\n");
fgets(str, sizeof(str), stdin);
for(int i = 0; i < strlen(str); i++)
{
if(islower(str[i])){
str[i] = toupper(str[i]);
}else{
printf("enterred\n");
str[i] = tolower(str[i]);
}
}
printf("%s\n", str);
return 0;
}
Upvotes: 2