#include <stdio.h>
int main(){
char testChar;
printf("%d\n", scanf("%c", &testChar));
return 0;
}
我只想打印扫描的字符数。但是,当我所有的输入都具有相同的输出时,即 1。
最佳答案
scanf()
返回成功扫描的项目数。所以,在你所有的运行中 scanf()
都成功了,因此你的程序打印了 1。
来自 scanf()
:
On success, these functions return the number of input items successfully matched and assigned; this can be fewer than provided for, or even zero, in the event of an early matching failure.
The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set to indicate the error.
关于c - 为什么此代码为所有输入打印 "1"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40157015/