回 帖 发 新 帖 刷新版面

主题:找高手排除错误!就一个错误了!

为什么用DEV-C++编译下边的程序总是过不去,只有一个错
"main must return int",求高手指点一下,小弟谢谢了!

#include "ctype.h"
#include "math.h"
#include "float.h"
#include "stdarg.h"
#include "io.h"
#include "stdio.h"
#include "string.h"
FILE *f;
void noblank(char &ch)
{
    while (ch==' '||ch=='\n')
        ch=fgetc(f);
}
//====================================================================
void identifier(char name[],char &ch)
{
    int i;
    for (i=0;i<10;i++)
        name[i]='\0';
    i=0;
    name[i]=ch;i++;
    ch=fgetc(f);
    while (('0'<=ch&&ch<='9')||('a'<=ch&&ch<='z')||('A'<=ch&&ch<='Z'))
    {
        name[i]=ch;
        i++;
        ch=fgetc(f);
    }
}
//====================================================================
int intconst(char &ch)
{
    int num=0;
    while ('0'<=ch&&ch<='9')
    {
        num=num*10+(ch-'0');
        ch=fgetc(f);
    }
    return num;
}
//====================================================================

回复列表 (共3个回复)

沙发

void main()
{
    char ch,name[20];
    char st1[10]={"#include"};
    char st2[10]={"main()"};
    char st3[10]={"{"};
    char st4[10]={"int"};
    char st5[10]={"}"};
    char st6[20]={"cout<<"};
    int num;
    f=fopen("prog.txt","r");
    if (f==NULL)
        //cout<<"no such file."<<endl;
    ch=fgetc(f);
    while (!feof(f))
    {
        noblank(ch);
        if ((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
        {
            identifier(name,ch);
            if (!strcmp(name,st1))  printf("${\n");
            else if (!strcmp(name,st2))  printf("$}\n");
            else if (!strcmp(name,st3))  printf("$int\n");
            else if (!strcmp(name,st4))  printf("$cout<<\n");
            else if (!strcmp(name,st5))  printf("$#include\n");
            else printf("$id,%s\n",name);
        }
        else if (ch>='0'&&ch<='9')
        {
            num=intconst(ch);
            printf("$intc,%d\n",num);
        }
        else switch(ch)
        {
            case'('://cout<<"lparen"<<endl;
                ch=fgetc(f);break;
            case')'://cout<<"rparen"<<endl;
                ch=fgetc(f);break;
            case'+'://cout<<"plus"<<endl;
                ch=fgetc(f);break;
            case'*'://cout<<"mult"<<endl;
                ch=fgetc(f);break;
            case';'://cout<<"semi"<<endl;
                ch=fgetc(f);break;
            case'='://cout<<"give value"<<endl;
                ch=fgetc(f);break;
            case'.'://cout<<"point"<<endl;
                ch=fgetc(f);break;
            default:break;
        }
    }fclose(f);
}

板凳

错误 是不是main程序不能用void 说明。
DEV-C++ 没用过,一般c里main不能用void声明,而且默认返回整数的。

3 楼

用了void就不能返回值了

我来回复

您尚未登录,请登录后再回复。点此登录或注册