2

私はこの簡単なプログラムを持っています:

#include <stdio.h>

int main()
{
    int c;
    while ( ( c = getchar()) != EOF)
        printf("%d %c\n", c, c);

    return 1; 
}

ただし、何らかの理由で実行すると、最後に追加の値 10 が得られます。

a
97 a
10 

b
98 b
10 

abc
97 a
98 b
99 c
10 

値 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; 
}
4

1 に答える 1