免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2164 | 回复: 2
打印 上一主题 下一主题

[求助]lex and yacc(2) 例子ch2-03运行不了 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-19 22:07 |只看该作者 |倒序浏览
新手,从网上down下来lex and yacc second 第二版例子
ch2-03,无法运行多文件单词计数程序。我是在redhat 9中试的,有没有哪位碰到过,谢谢

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
2 [报告]
发表于 2008-06-19 23:18 |只看该作者
我想你在问问题的时候,最好应该把代码附上.
然后给出你运行的例子,包括你是如何编译的.
像这样

  1. $ echo Hello,world!
  2. Hello,world!
复制代码

论坛徽章:
0
3 [报告]
发表于 2008-06-19 23:37 |只看该作者
谢谢提醒,我考虑代码比较长一点,就没有贴上来

经过调试,确定是作者的代码有误

yywrap()
{

        FILE *file;  此处没有初始化为null,导致后面一直返回0,死循环了
        if ((currentFile != 0) && (nFiles > 1) && (currentFile < nFiles)) {
                /*
                 * we print out the statistics for the previous file.
                 */
                printf("%8lu %8lu %8lu %s\n", lineCount, wordCount,
                        charCount, fileList[currentFile-1]);
                totalCC += charCount;
                totalWC += wordCount;
                totalLC += lineCount;
                charCount = wordCount = lineCount = 0;
                fclose(yyin);   /* done with that file */
        }

        while (fileList[currentFile] != (char *)0) {
                file = fopen(fileList[currentFile++], "r");
                if (file != NULL) {
                        yyin = file;
                        break;
                }
                fprintf(stderr,
                        "could not open %s\n",
                        fileList[currentFile-1]);
        }
        return (file ? 0 : 1);  /* 0 means there's more input */
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP