D
Dave Cooke
Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;
just to test in my main method I tried to initialize the
listNodePtr variable to null like this...
listNodePtr *head = NULL;
First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
that listNodePtr is an alias to the struct ln. So my statement
above should be legal. Is It?
When I try to pass my new listNodePtr variable *head to my
listInsert method like........
listInsert(head,1,2);
it doesn't work. It builds but at run time my program hangs
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.
The method definition looks like...
void listInsert(listNodePtr *list, int key, int value)
I am assuming the body of the method is correct as this code
was given to us to use by my Prof.
Please help what am I doing wrong during my initialization?
How do I use structs defined like the one above?
Thanks in advance.
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;
just to test in my main method I tried to initialize the
listNodePtr variable to null like this...
listNodePtr *head = NULL;
First as far as I understand listNode and *listNodePtr are
variables of type ln. However I have also learned, so I thought,
that listNodePtr is an alias to the struct ln. So my statement
above should be legal. Is It?
When I try to pass my new listNodePtr variable *head to my
listInsert method like........
listInsert(head,1,2);
it doesn't work. It builds but at run time my program hangs
when inside the listInsert method the first if condition
tries to determine of the listNodePtr *list is null or not.
i.e. if( *list == NULL )..... this is where the program quits.
The method definition looks like...
void listInsert(listNodePtr *list, int key, int value)
I am assuming the body of the method is correct as this code
was given to us to use by my Prof.
Please help what am I doing wrong during my initialization?
How do I use structs defined like the one above?
Thanks in advance.