0

Cでこのプログラムを実行した後、Ctrl + Zを何度押してもcmdから終了できません。このプログラムは、タブ、改行、および新しい空白の数をカウントします

main()
{
  int c, nl, nb, nt;

  nl = 0;
  nb = 0;
  nt = 0;
  while ((c == getchar()) != EOF){ 
      if (c == '\n')
        ++nl;
      if (c == '\t')
        ++nt;
      if (c == ' ')
        ++nb; 
      }   
  printf("%d %d %d\n", nl, nt, nb);

}

Ctrl + C を押すと、終了するだけです。

4

2 に答える 2

2

Ctl+DEOF入っUNIX based systemsています。停止したいときはいつでも ctl+D を押す必要があります

Ctl+Z停止したいときはいつEOFでもWindowsctl + zを押す必要があります。

while ((c == getchar()) != EOF) ==> while ((c = getchar()) != EOF)   
          ^^                                  ^  
于 2013-09-03T09:03:50.473 に答える
0

Assuming you're on Windows, the situation is that you basically have to do the ctrl+Z at the beginning of a line -- i.e., you have to have hit enter, then do the ctrl+Z, then (depending on how the input is being read) possibly enter again.

You can also use F6 to signal the end of the input. At least in most cases, this will work even when/if it does not immediately follow an enter.

于 2013-09-03T10:58:10.660 に答える