があなたのエラーを再現できませんでした。私は、
#include <stdio.h>
main() {
int nc = 0, ch;
while ((ch = getchar()) != EOF) {
printf("%d\n", ch);
++nc;
}
printf("nc - %1d\n", nc);
}
をいくつかのデバッグ文を追加し、Windows上でgcc
でそれを試してみました:
E:\temp>gcc eof.c
E:\temp>a
^Z
nc - 0
E:\temp>a
foo bar
102
111
111
32
98
97
114
10
^Z
nc - 8
し、Visual Studioの2008年:
E:\temp>cl eof.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
eof.c
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:eof.exe
eof.obj
E:\temp>eof
^Z
nc - 0
E:\temp>eof
foo bar
102
111
111
32
98
97
114
10
^Z
nc - 8
私はあなたがそれが2を出力」を意味すると仮定します"、" ncに2を乗じた "ではありません。私は、Ctrl + Zは2回のキーストロークを生成していると思います。 –
'enter'はキーストロークです。 –
ああ、今見ているので、すべてのキーストロークが1回ではなく2回登録されたのはこのためです。 – Emryss