gpt4 book ai didi

c - 执行程序时出错

转载 作者:行者123 更新时间:2023-11-30 17:28:55 25 4
gpt4 key购买 nike

我在代码块中执行此代码时遇到一些问题。当我运行代码时,它一切正常,直到 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;
}

最佳答案

将行 scanf("%c", option); 更改如下,

scanf("%c", &option);

现在程序可以正常运行了。 &%c 所必需的。

关于c - 执行程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25860413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com