print_all_lists(*g, n_vertices); /* n_vertices is the sizeof the array; */

means I can't seem to get the iterative call to print working...

Code:

void print_all_lists(node_ptr arr, int arr_length)
{
int k = 0;

while(k < arr_length)
{
printf("\n\n");
printf("List: %d\n", k);

print(arr);

k++;
}
}

Obviously print(arr) in nodes.c is going to repeatedly print the first list but every way I've tried to increment down (like I did in main) just makes the program crash.

Could anyone offer any advice into what I am missing in my understanding. Why could I do this in main but can't seem to do so from other files?

05-14-2007

zacs7

Why not just pass a pointer to the first node in print_all_lists?

such as

Code:

node_ptr * g;

print_all_lists(g, n_vertices); /* n_vertices is the sizeof the array; */

void print_all_lists(node_ptr * arr, int arr_length)
{
/* ... */
}

I would suggest a linked list.

05-14-2007

occams razor

Hi Zacs7, yes it is already a pointer to a linked list...

what I'm saying is from main() the code using 'g' will print out the entire set of lists iterating down the array of pointers...

but when I try from a function on another file I can't get it to print out all of the lists in the same way by passing a 'print(*arr++)' call for example.

I'll hunt up the reason today but have just become very curious as to why exaclty I could pass that *g++ from main but can't achieve the same result from a function on the same file as print(node_ptr the_list).

Thanks for the reply though, feedback is appreciated.

05-15-2007

itsme86

Sounds like a typical "defined a struct in a header file, but didn't recompile all .c files that use the definition" problem to me.

e.g. If you change a header file, you should recompile all files that include that header.