调用main函数中未定义功能() [英] call to undefined function in function main()

查看:429
本文介绍了调用main函数中未定义功能()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我使用一个被称为主函数的功能,它给这个错误:调用函数主要未定义功能()
我使用的Turbo C ++编译器4.5版和Windows Vista终极的Service Pack 2
你能告诉这头文件或别的东西,是被使用。我初学C语言编写。

产生这个错误的一个例子:

 #包括LT&;&stdio.h中GT;main()的
{
  INT I;
  INT标记[] = {1,2,3,4,5,6,7};  对于(i = 0; I< = 6;我+ +)显示(标记[I]);
}显示(INT米)
{
  的printf(%d个M);
}


解决方案

您需要使用之前定义(或至少声明)的函数。您可以通过包含一个头,其中包括为函数的声明(或样机),或声明或定义可以直接手头的源文件中包含做到这一点。例如:

 的#include<&stdio.h中GT;DOIT无效(){
    //上述&lt声明通话功能;文件stdio.h>
    的printf(从主调用的函数);
}诠释主(){
    //调用函数上面定义。
    DOIT();
    返回0;
}

whenever i use a function which is called in main function, it gives this error: Call to undefined function in function main() i am using turbo c++ compiler version 4.5 and windows vista ultimate service pack 2 Can you tell which header file or something else is to be used. I am beginner in C language.

An example which produces this error:

#include<stdio.h> 

main( ) 
{ 
  int i ; 
  int marks[ ] = { 1, 2, 3, 4, 5, 6, 7 } ; 

  for ( i = 0 ; i <= 6 ; i++ ) display ( marks[i] ) ; 
} 

display ( int m ) 
{ 
  printf ( "%d ", m ) ; 
}

解决方案

You need to define (or at least declare) any function before use. You can do that by including a header that includes a declaration (or prototype) for the function, or the declaration or definition can be contained directly in the source file at hand. For example:

#include <stdio.h>

void doit() { 
    // call function declared in <stdio.h>
    printf("Function called from main");
}

int main() {
    // call function defined above.
    doit();
    return 0;
}

这篇关于调用main函数中未定义功能()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆