-4

The compiler gives the following error with the code below, at the location of the added comment:

error: unknown type name 'node'

#include <stdio.h>

typedef struct node
{
    int info;
    node *sig; //<-- error: unknown type name 'node'
} nodeL;

int main(void) {
    nodeL n;
    printf("%x\n", n.info);

    return 0;
}

How can I solve it?

AlbusMPiroglu
  • 645
  • 3
  • 13
Alejandro Caro
  • 998
  • 1
  • 10
  • 22

2 Answers2

2

You must keep in mind that C compiler don't know what is node or nodo (you typed it wrong in the struct name probably), it's not a C primary type. At this point nodo is a struct type and you must "say" it to the compiler, like:

typedef struct nodo
{
    int info;
    struct nodo *sig; 
} nodeL;

The atribute nodo *sig; inside the struct declares a member sig that is a defined pointer to the struct type.

-1
typedef struct nodo
{
    int info;
    struct nodo *sig; // Rather than: node *sig;
} nodeL;

It looks like your structure name node is what you are referencing inside the structure. nodo not node.

Perhaps there is a mis-understanding that nodo (or node) is a C type. It is not a type. However struct nodo is defined in the question code.

Mahonri Moriancumer
  • 5,993
  • 2
  • 18
  • 28