输入一串小写字母回车后有个换行,这个换行让循环结束的,可以增加处理输入的字符为换行符的情况即可。
修改如下:
#include <stdio.h>
int main(void){
char ch;
scanf("%c",&ch);
// 如果要测试多行数据,增加处理输入的字符为换行符的情况
while(ch>='a'&&ch<='z'||ch=='\n'){
// 如果不是换行,则将小写字母转为对应的大写字母
if(ch!='\n'){
ch=ch+'A'-'a';
}
printf("%c",ch);
scanf("%c", &ch);
}
return 0;
}
你输入的数据是什么,如果都是小写字母才能继续
楼上正解,取决于输入的数据
【相关推荐】
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 1024
int main()
{
char src[MAX_SIZE] = {0};
int i = 0;
printf("Please input string : ");
gets(src);
printf("string = ");
while (src[i] != '\0')
{
printf("%c", src[i]);
i++;
}
printf("\n");
return 0;
}
Please input string : congcong123456
string = congcong123456