我有这个简单的程序:
#include <stdio.h>
int main()
{
int c;
while ( ( c = getchar()) != EOF)
printf("%d %c\n", c, c);
return 1;
}
Run Code Online (Sandbox Code Playgroud)
但是由于某些原因,在执行时我最终获得了额外的值10:
a
97 a
10
b
98 b
10
abc
97 a
98 b
99 c
10
Run Code Online (Sandbox Code Playgroud)
什么是价值10,它来自哪里?如何阻止它发生?
解:
#include <stdio.h>
#include <ctype.h>
int main()
{
int c;
while ( ( c = getchar()) != EOF)
{
if ( isprint (c))
{
printf("%d %c\n", c, c);
}
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)