Page 52
Rewrite the function lower, which converts upper case letters to lower case, with a
conditional expression instead of if-else
.
#include <stdio.h>
#define STR_LEN 1000
void lower(char str[], int len);
int main()
{
char str[STR_LEN] = "AbCdEfGh";
lower(str, STR_LEN);
printf("%s\n", str);
}
void lower(char str[], int len)
{
for (int i = 0; i < len; i++) {
str[i] = str[i] >= 'A' && str[i] <= 'Z' ? str[i] + 32 : str[i];
}
}