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

struct tnode*talloc(int data)
{

    struct tnode*p=(struct tnode*) malloc(sizeof(struct tnode))
    if (p!=NULL)
    {
        p->data=data;
        p->next=NULL;
       p->right=NULL;
    }
    return p;
}

int main(){}

I am getting a [error: 'NULL' undeclared] error, Any help would be greatly appreciated.

Recommended Answers

All 2 Replies

p->next=NULL;

struct tnode doesn't contain a member next

struct tnode*p=(struct tnode*) malloc(sizeof(struct tnode));

Missing semicolon. Casting the return of malloc is not recommended in C. Just include the header file stdlib.h

Try including the header file stdio.h

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.