char str[100];
puts("Enter the string: ");
// fgets(str, 100, stdin);
gets(str);
for (int i = 0; i < strlen(str); i++) {
if (isupper(str[i]) > 0) {
str[i] = tolower(str[i]);
}
if (islower(str[i]) > 0) {
str[i] = toupper(str[i]);
}
}
printf("%s", str);
MY TOLOWER FUNCTION DOES NOT WORK FOR EXAMPLE
MY INPUT IS: TURAL muzafarov
but it returns
TURAL MUZAFAROV
You are doing back 2 back two. operation. first you convert string to lowercase then you do uppercase conversion. please remove below code which converts string into uppercase.
EDIT: C Reference says about toupper()
hence, below lines are not correct. the argument to toupper needs to be converted to unsigned char to avoid the risk of undefined behavior.
change to
also need to change below block of code
changed to
output: