开发者社区> 问答> 正文

C语言基础单词计数问题?求救,急急急!!! 400 请求出错 

//这是一个计算字符数 ,单词数,行数的小算法,但是在vc++6.0中运行出现编译错误

//感觉上应该没有问题呀!求救!!

#include <stdio.h>

#define OUT 0;

#define IN 1;

 main ()

 {

int c ;

int nl,nw,nc,state;//nl行数,nw单词数,nc字符数

nl = nw = nc = 0;

state = OUT;

while ((c = getchar())!=EOF)

{

putchar(c);

if(c=='\n')

{

nl++;

}

if(c==' '||c=='\t'||c=='\n')

{

state = OUT;

}

    else if(state == OUT)

{

state = IN;

nw++;

}

nc++;

}

printf("%d,%d,%d",nc,nw,nl);

 

 }

//错误如下

C:\Users\liyingjie\Desktop\chapter1-5-4.c(3) : warning C4005: 'IN' : macro redefinition

        c:\users\liyingjie\desktop\chapter1-5-4test.c(0) : see previous definition of 'IN'

C:\Users\liyingjie\Desktop\chapter1-5-4.c(21) : error C2143: syntax error : missing ')' before ';'

C:\Users\liyingjie\Desktop\chapter1-5-4.c(21) : error C2059: syntax error : ')'

执行 cl.exe 时出错.

 

展开
收起
黄一刀 2020-05-26 20:32:18 570 0
1 条回答
写回答
取消 提交回答
  • #define后面不加分号######

    #define OUT 0;

    #define IN 1;
    改为
    #define OUT 0
    #define IN 1

    是你要的意思么?
    ######嗯,谢谢,十分感谢!######

    引用来自“billzheng”的答案

    #define OUT 0;
    #define IN 1;
    改为
    #define OUT 0
    #define IN 1

    是你要的意思么?
    就是错在来着,谢谢大神
    ######回复 @billzheng : 哈哈哈哈哈######慢给Leo108好几次了,都是因为尽量去多码几个字,让你们能看懂。 以后直接贴(开玩笑呢)######

    #define 后面为什么不能叫分号 其实加分号编译也没问题

    只是加了之后会这样

    #define max 10;
    if(max)
    {
        //...
    }
    
    //然后编译的时候会被替换成 
    if(10;)
    {
       //....
    }

    ######回复 @魔方帅帅 :??? 有问题么 宏确实是这样被替代的么######这个不行吧,你好像把表达式和语句弄混了。。######为什么用C,用正则鉴定字词,用hash记录次数,很快,很简单
    2020-05-27 10:19:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
当泛型遇上协议 立即下载
小程序 大世界 立即下载
《15分钟打造你自己的小程序》 立即下载