gpt4 book ai didi

c - xcode 中 Scanf() 的奇怪行为

转载 作者:太空宇宙 更新时间:2023-11-04 03:51:30 26 4
gpt4 key购买 nike

int P;
printf("Print a Character:");
scanf("%d",&P);
printf("\n The character you pressed was %d",P);

没有我输入任何数字,输出:

“打印一个字符:

你按下的字符是-1073750520"

你知道为什么会这样吗?我正在使用 Xcode。

最佳答案

我认为 stdin 流中已经存在一些东西。所以冲洗流可能会有所帮助。

scanf(); 之前尝试 fflush(stdin);

但是 fflush(stdin) 是未定义的行为。

关于c - xcode 中 Scanf() 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20321421/

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