Yet another pointers problem in C
I got my double linked list to work (albeit with some warning messages that I don't understand yet. I have now moved on to produce a program that produces a tree structure. This time I am getting the error "dereferencing pointer to incomplete type" on lines 22,23 and 24 and I don't understand why. I am also getting "passing arg 1 of `initialise_node' from incompatible pointer type" on line 31, which I also don't understand. Any help would be gratefully received. I will post my full set of C examples on the web when I have got them working. (I am using gcc 3.2.1 on RedHat 9).
/* Example to use pointers to construct a 4 level tree with a 4 digit
code to locate nodes within the tree*/
my program pointertree.c:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
int h_code[4];
char nodename[30];
struct node *parent, *child[10];
} node;
int main (void)
{
void initialise_node(struct node *n)
/* a procedure for intialising nodes */
{
int j; /* local variable */
for (j=0; j<3; ++j) n->h_code[j] = 0; /*line 22 with error */
for (j=0; j<3; ++j) printf("node->h_code[%i] = %i\n",n->h_code[j]);
for (j=0; j<10; ++j) n->child[j] = 0; /* point children to null */
}
printf("Starting program\n");
node *rootnode, *newnode;
rootnode = (node *) malloc (sizeof (node));
printf("calling initialise node\n");
initialise_node(rootnode); /* line 31 with error */
}
Compiler errors:
[nmansys@mmme1 c_examples]$ gcc pointertree.c
pointertree.c: In function `initialise_node':
pointertree.c:22: dereferencing pointer to incomplete type
pointertree.c:23: dereferencing pointer to incomplete type
pointertree.c:24: dereferencing pointer to incomplete type
pointertree.c: In function `main':
pointertree.c:31: warning: passing arg 1 of `initialise_node' from incompatible pointer type
|