A question about pointers in functions
I'm programming (in Ansi C) an adjacency list of an array with each element pointing to a list of structs and compiling with
gcc -Wall -ansi -pedantic -O *.c
my question is simply that from within main I can easily move down and print out all of these lists BUT...
if I try to do this with a function I can't seem to get it to print more than the first list at array[o].
for example in main this prints all lists
Code:
k = 0;
while(k < n_vertices)
{
printf("\n\n");
printf("List: %d\n", k);
print(*g++);
k++;
}
while in my file nodes.c in the same directory this call from main
Code:
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?