这是我的程序,将从标准输入中输入的所有字母大写。但是有些输出很奇怪。例如,如果输入是“lorem ipsum”,输出将是“LOREM IPSUMS?”。如果输入是单个字符,例如“m”,则输出将为“MZ#X?” . “S?” 和“Z#X?” 不应该在这里,但它们附加到输出。
为什么会发生这种情况?
#include <stdio.h>
#include <ctype.h>
int main(void){
char input;
char upper[100];
int count = 0;
while((input = getchar())){
if(input == '\n')
break;
if(input >= 'a' && input <= 'z')
input = toupper(input);
*(upper + count) = input;
count++;
}
printf("%s\n", upper);
return 0;
}