iptton 发表于 2006-10-25 12:42

[C]一段从书上直接抄来的代码,运行不正确

#include<stdio.h>
#include<ctype.h>

int found_next_word(void);

int main(void)
{
   int   word_count=0;


   while (found_next_word() == 1)
      ++word_count;

   printf("Number of words = %d\n\n", word_count);

   getch();
   return 0;
}

int found_next_word(void)
{
   int   c;

   while (isspace(c=getchar()))
      ;                         /*skip white space*/
   if (c != EOF){             /*found a word*/
      while ((c = getchar()) != EOF && !isspace(c))
         ;

      return 1;
   }
   return 0;
}



似乎无法读取回车
WIN TC2

[ 本帖最后由 iptton 于 2006-10-25 13:05 编辑 ]

iptton 发表于 2006-10-25 13:05

http://bbs.cfan.com.cn/viewthread.php?tid=413219

EOF:
Windows: Ctrl+Z
Unix: Ctrl+U (好像是这个)

黯然销魂 发表于 2006-10-25 22:21

编译器不一样所致吧...

iptton 发表于 2006-10-25 23:02

运行正确的。。。

只是对EOF理解错误。。。

同学遇到的问题。。。

#2上的说明了:EOF在DOS上应该是 Ctrl+Z  而非 回车
页: [1]
查看完整版本: [C]一段从书上直接抄来的代码,运行不正确