我在代码块中执行此代码时遇到了一些麻烦。当我运行代码时,它一直运行良好,直到 scanf 行,之后发生错误并停止代码运行。
#include <stdio.h>
#include <ctype.h>
int main(){
char lower, upper, option;
puts("Type '.' to end the program.");
printf("U-to upper\nL-to lower\n");
fflush(stdin);
scanf("%c", option);
switch(option){
case 'u':
case 'U':
do{
fflush(stdin);
lower=getchar();
upper=toupper(lower);
putchar(upper);
}while(lower!='.');
break;
case 'l':
case 'L':
do{
fflush(stdin);
upper=getchar();
lower=tolower(upper);
putchar(lower);
}while(upper!='.');
break;
}
return 0;
}