练习2-10 重新编写将大写字母转换为小写字母的函数lower,并用田间表达式替代其中的if-else结构。
#include <stdio.h>
#define MAXLEN 100
void lower(char s[]);
int main()
{
int i, c;
char s[MAXLEN];
i = 0;
printf("Please input string:\n");
while ((c = getchar()) != EOF && i < 100)
{
s[i] = c;
++i;
}
s[i] = '\0';
lower(s);
printf("Lower:%s\n", s);
return 0;
}
void lower(char s[])
{
int i = 0;
while (s[i] != '\0')
{
s[i] = (s[i] <= 'Z' && s[i] >= 'A') ? (s[i] + 32) : s[i];
printf("%c\n",s[i]);
i++;
}
return;
}