November 12th, 2010, 04:59 PM
I keep trying different ways of writing a compare function but when I run the program I keep getting a seg fault at the qsort function call.
And the qsort call:
int comp(const void *a, const void *b)
const Wordrec **l = (const Wordrec **) a;
const Wordrec **r = (const Wordrec **) b;
return strcmp((*l) -> data, (*r) -> data);
record is a pointer to a pointer (**record), used like a dynamic array and numwords is the number of words/records.
qsort(record, numwords, sizeof(Wordrec), comp);
This is homework. I'm supposed to read in a text file, read out a text file with all the lines a certain size or less, and read out a sorted text file that has one occurrence of each word (without worrying about punctuation) and the number of times that word occurred.
Everything but the sorted part is done, I just can't seem to get the qsort function to work right.
Any help will be greatly appreciated. Thank you.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!