工大后院

 找回密码
 加入后院

扫一扫,访问微社区

QQ登录

只需一步,快速开始

搜索
查看: 1413|回复: 3

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

[复制链接]
发表于 2006-10-25 12:42 | 显示全部楼层 |阅读模式
#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 编辑 ]
 楼主| 发表于 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 | 显示全部楼层
编译器不一样所致吧...
回复

使用道具 举报

 楼主| 发表于 2006-10-25 23:02 | 显示全部楼层
运行正确的。。。

只是对EOF理解错误。。。

同学遇到的问题。。。

#2上的说明了:EOF在DOS上应该是 Ctrl+Z  而非 回车
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入后院

本版积分规则

QQ|Archiver|手机版|小黑屋|广告业务Q|工大后院 ( 粤ICP备10013660号 )

GMT+8, 2025-8-31 03:07

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表