I have the same professor: I have read the forum:
It is very helpful understanding the concept of the function but I'm not sure if I am using it right...
Here is my code.. Let me know if I am on the right track...
Assume that I have an array of 10 linked lists in which the linked lists holds ints
Now I would like to sort the list calling the list_map(); function
So my main looks something like this:
int x = 10;
LLIST *mylist[x];
bzero(mylist, sizeof(LLIST *)*x);
.
.
for(i=0; i< 10; i++)
{
//Segfalt
list_map(mylist[i],sort);
}
my list_map looks like:
void list_map( LLIST *list, void (*f)(void *) )
{
printf("Sort");
f(list);
}
and Sort:
void sort(LLIST *n) {
//Sort Code
}
The error I get is Segmentation fault when I run it.
Please excuse the lack of code, I know my sort function works, I have tested it already and it prints out each list. If you need to see something in more detail let me know I will provide it.