user1003967
user1003967

Reputation: 157

C getting an "unknown type " error when i try to assign a struct node in a struct node

I am trying to make a struct Node, that links to other Nodes. in the code below

typedef struct Node{

   Node *children[10];

}Node;

When i try and compile i get the error

Error unknown type name 'Node'

I'm pretty sure i should be able to assign a Node from inside the Struct Node. Can anyone explain why this isnt working.

Upvotes: 0

Views: 231

Answers (1)

Vlad from Moscow
Vlad from Moscow

Reputation: 310930

Within the structure definition the name Node is yet undefined. There is defined only the type specifier struct Node. So write

typedef struct Node{

   struct Node *children[10];

}Node;

Or you could write

typedef struct Node Node;
struct Node
{
    Node *children[10];
};

Upvotes: 2

Related Questions