Read the file into a linked list, sort it, then write it back out. That will work for files that are not very large. For really huge files (1+gig) there are file sort programs you can get (see google).
a) Read the words into a linked list of structures. If the word is already in the list then just increment the structure's counter variable member. If the word is not in the list, create a new structure and add it to the list in sorted order or just to the end of the list.
struct word
{
char* sword;
int count;
};
b) just iterate through the linked list and print out the words
c) If you add new nodes in sorted order then this option is the same as the previous one. Otherwise if you just added new words to the end of the list then you will have to sort the list first.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
void clearString(char *string)
{
memset(string, '\0', sizeof(string));
}
That will not work because sizeof( any pointer here ) always = 4 with 32-bit compilers. To erase a character array all you have to do is set the first character to 0.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343