c - warning: implicit declaration of function ‘printf’

C

C Problem Overview


I know alot of similar questions were asked before but i couldn't find something that would fix this warning i get:

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

Occurs here:

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

and a similar warning:

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

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

I really want to understand what is wrong so i won't do that again in the future.

C Solutions


Solution 1 - C

You need to include the appropriate header

#include <stdio.h>

If you're not sure which header a standard function is defined in, the function's man page will state this.

Solution 2 - C

You need to include a declaration of the printf() function.

#include <stdio.h>

Solution 3 - C

the warning or error of kind IMPLICIT DECLARATION is that the compiler is expecting a Function Declaration/Prototype..

It might either be a header file or your own function Declaration..

Solution 4 - C

warning: incompatible implicit declaration of built-in function 'printf'

warning: incompatible implicit declaration of built-in function 'scanf'

the above warnings of compiler says that there is need to include declaration of printf and scanf i.e. include appropriate header

#include <stdio.h>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomView Question on Stackoverflow
Solution 1 - CsimoncView Answer on Stackoverflow
Solution 2 - Coleg_gView Answer on Stackoverflow
Solution 3 - CRaghu Srikanth ReddyView Answer on Stackoverflow
Solution 4 - CAmogh24View Answer on Stackoverflow