Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c - warning: implicit declaration of function ‘printf’

Tags:

c

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 function ‘printf’ [-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.

like image 962
Tom Avatar asked Dec 28 '12 11:12

Tom


2 Answers

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.

like image 65
simonc Avatar answered Sep 29 '22 21:09

simonc


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

#include <stdio.h> 
like image 45
oleg_g Avatar answered Sep 29 '22 20:09

oleg_g