SuperString SuperString - 3 months ago 8
C Question

Two or more data types in declaration specifiers error

I am pretty new to C.

I am getting this error:


incompatible implicit declaration of built-in function ‘malloc’


Even when I fix the code based on the answers to include
<stdlib.h>
, I still get:


two or more data types in declaration specifiers


When trying to do this:

struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}

struct tnode * talloc(int data){
struct tnode * newTnode;
newTnode = (struct tnode *) malloc (sizeof(struct tnode));
newTnode->data = data;
newTnode->left = NULL;
newTnode->right = NULL;
return newTnode;
}


How do I fix it?

sth sth
Answer

You have to put ; behind the struct declaration:

struct tnode
{
    int data;

    struct tnode * left;
    struct tnode * right;
}; // <-- here