【发布时间】:2012-11-13 23:27:00
【问题描述】:
我刚刚看到这在技术上是可行的,唯一我无法解决的错误是每次测试时打印的最后一个 ASCII 字符,我也在不使用 name 变量,我的意思是只要对 ASCII 中的任何小写字母减去 32 就应该给我他们的大写字母,而且确实如此,但我很好奇为什么我会得到一个额外的字符,我在屏幕上看到的显然是 Û。
#include <stdio.h>
main()
{
char name[22];
int i;
fputs("Type your name ",stdout);
fgets(name,22,stdin);
for (i = 0; name[i] != '\0'; i = i + 1)
printf("%c",(name[i])-32); /*This will convert lower case to upper */
/* using as reference the ASCII table*/
fflush(stdin);
getchar();
}
【问题讨论】:
标签: ascii ctype tolower toupper