【发布时间】:2018-10-23 14:59:19
【问题描述】:
int main(void)
{
char s[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
i = 0;
while (s[i] != '\0') {
printf("%c -> %c\n", s[i], lower(s[i]));
i++;
}
return 0;
}
int lower(int c)
{
return (c >= 'A' && c<= 'Z') ? c + 'a' - 'A' : c;
}
这是将所有字母转换为小写的程序。所以在解决方案中他们使用了一个较低的函数,但我不知道他们为什么使用 int 作为返回类型。
【问题讨论】:
-
我可能是错的,但我相信这是因为它会将其解释为 ASCII 码而不是字符
-
因为在 C 中,字符文字并不是真正的
char,而是int。 -
您是指
islower还是tolower?lower有一个return类型的int因为你是这样写的。 -
请注意,您的
lower函数可能不适用于 C 官方支持的其他字符编码。 -
请注意,
lower()作为int或char的结果无论如何都会转换为int作为...的参数printf()。