简体   繁体   English

我无法在 Dev C++ 中编译一个简单的 C 函数程序?

[英]i'm unable to compile a simple C function program in Dev c++?

I'm trying to compile in Dev-C++, program is:我正在尝试用 Dev-C++ 编译,程序是:

main( )
{
    message( ) ;
    printf ( "\nCry, and you stop the monotony!" ) ;
}

message( )
{
    printf ( "\nSmile, and the world smiles with you..." ) ;
}

Errors are:错误是:

E:\Dev\fn.cpp [Error] 'message' was not declared in this scope
E:\Dev\fn.cpp [Error] ISO C++ forbids declaration of 'message' with no type [-fpermissive]

Edit: Silly mistake.编辑:愚蠢的错误。 Was compiling a c program as cpp正在将c程序编译为cpp

Firstly, compile your C code as C code, not C++ code.首先,将您的 C 代码编译为 C 代码,而不是 C++ 代码。 The extension of C code should be .c , not .cpp . C 代码的扩展名应该是.c ,而不是.cpp

Then, recognize that there may be wrong things in books and correct code.然后,认识到书中可能有错误的东西和正确的代码。 You shouldn't omit types of return value and arguments, and functions used should be declared before it is used.你不应该省略返回值和参数的类型,并且使用的函数应该在使用之前声明。

Try this:尝试这个:

#include <stdio.h> /* declaration of printf() will be here */

/* bring this function before using */
void message(void)
{
    printf ( "\nSmile, and the world smiles with you..." ) ;
}

int main(void)
{
    message( ) ;
    printf ( "\nCry, and you stop the monotony!" ) ;
    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM