C语言警告:隐式声明函数'printf'

67

我知道很多类似的问题已经被问过了,但我找不到能够解决我遇到的这个警告的东西:

MyIntFunctions.c:19:2: warning: implicit declaration of functionprintf[-Wimplicit-function-declaration]

发生在这里:

void IntPrint (const void *key)
{
    printf("%d", *(int*)key); // line 19
    printf("\t-->\t");
}

还有一个类似的警告:

MyStringFunctions.c:22:2: warning: implicit declaration of functionprintf’ [-Wimplicit-function-declaration]

void StringPrint (const void *key)
{
    printf("%s",(char*)key); //line 22
    printf("\t-->\t");
}

我真的希望能够理解哪里出了问题,这样以后就不会再犯同样的错误了。


7
你考虑过包含 <stdio.h> 吗? - WhozCraig
2
请展示一下如何包含头文件。 - Adam Sznajder
4个回答

105

你需要包含适当的头文件

#include <stdio.h>

如果您不确定标准函数定义在哪个头文件中,该函数的man页面将说明此信息。


16

你需要包含printf()函数的声明。

#include <stdio.h>

3

IMPLICIT DECLARATION警告或错误是指编译器期望函数声明/原型。这可能是一个头文件或您自己的函数声明。


-1

警告:printf 内建函数的隐式声明不兼容

警告:scanf 内建函数的隐式声明不兼容

编译器上述警告说明需要包含声明 printfscanf,即需要包含适当的头文件。

#include <stdio.h>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接