c – Two or more data types in declaration specifiers error

c – Two or more data types in declaration specifiers error

You have to put ; behind the struct declaration:

struct tnode
{
    int data;

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

Your original error was because you were attempting to use malloc without including stdlib.h.

Your new error (which really should have been a separate question since youve now invalidated all the other answers to date) is because youre missing a semicolon character at the end of the struct definition.

This code compiles fine (albeit without a main):

#include <stdlib.h>

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;
}

c – Two or more data types in declaration specifiers error

Implicit declaration means that youre trying to use a function that hasnt been formally declared.

You probably forgot: #include <stdlib.h> which includes the function declaration for malloc.

Leave a Reply

Your email address will not be published.