You need to add:
#include <stdlib.h>
This file includes the declaration for the built-in function malloc
. If you don't do that, the compiler thinks you want to define your own function named malloc
and it warns you because:
int
, which isn't compatible with the built-in malloc
, which takes a size_t
and returns a void*
).You haven't done #include <stdlib.h>
.
You need to include the header file that declares the function, for example:
#include <stdlib.h>
If you don't include this header file, the function is not known to the compiler. So it sees it as undeclared.
Make a habit of looking your functions up in help.
Most help for C is modelled on the unix manual pages.
Using :
man malloc
gives pretty useful results.
Googling man malloc
will show you what I mean.
In unix you also get apropos for things that are related.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With