0

为什么这个 C 程序不能编译,错误消息是什么意思:

#include <stdio.h>
int main() {
    char op = ' ';
    char cont = ' ';
    int tal1 = 0;
    int tal2 = 0;
    int result;
    int ok = 1;
    printf("Welcome\n");
    do  {
        printf("Which one (+ - * /)? ");
        scanf("%c", &op);  fflush(stdin);
        printf("Number?: ");
        scanf("%d", &tal1); fflush(stdin);
        printf("Number: ");
        scanf("%d", &tal2);   fflush(stdin);
        ok=1;
        switch(op){
        case '+': 
            result=tal1+tal2;
            break;
        case '-':
            result=tal1-tal2;
            break;
        case '*':
            result=tal1*tal2;
            break;
        case '/':
            result=tal1/tal2;
            break;
        default:
            printf("Wrong\n");
            ok=0;
            break;
        }
        if(ok)
            printf("Answer: %d\n", result);
        printf("Continue? (j/n)"); fflush(stdin);
    }while (cont == 'j');
    printf("Thanks!\n");
    return 0;
}

错误混乱:错误 4 错误 LNK2019:未解析的外部符号 _WinMain@16 在函数 ___tmainCRTStartup MSVCRTD.lib 中引用 错误 5 致命错误 LNK1120:1 未解析的外部

4

2 回答 2

1

检查您的链接器设置(Pproject Properties->Linker->System)。

SubSystem 属性应设置为CONSOLE

于 2009-09-24T11:10:52.833 回答
0

您正在编译一个 Windows (win32) 应用程序,但具有 main() 函数而不是 WinMain()。

您应该将项目的类型更改为某种控制台应用程序(不记得确切的名称)或阅读有关编写 Windows 应用程序的信息。

The problem is that win32 applications use WinMain() for their main function and implement a message loop in there. So when you try to compile win32 application without defining a WinMain() function the compiler complains about just that. Similar thing would happen if you would write a console application and would not provide a main() function.

于 2009-09-24T11:11:17.373 回答