The code that you have written right now will open the file, read it one character at a time, and print those characters back to the console. If you just need to print the contents of the file in sorted order and don't need to manipulate the file contents later on, you could consider using the system command to run the command-line tool sort, which does this for you. For example:
system("sort suspectfile.txt");
This will handle everything for you, though it won't actually load the data into your program.
If you need to load the data into your program and then go sort it, your best bet is probably to load the file contents into an array (I'll leave those details to you, since you know the file format better than I do) and then to use the qsort function to arrange the data into ascending order. qsort needs you to provide it with an array to sort, the size of each element in the array, the number of elements, and a comparison function. Here's one way you could use it:
/* String comparison function for use by qsort. The parameters will be * void*'s that actually point at char*'s. */ int string_comparator(const void* one, const void* two) { return strcmp(*(char**)one, *(char**)two); } char** file_contents_array = /* ... load the file ... */ qsort(file_contents_array, /* number of elements in the array */, sizeof(char *), string_comparator);
You now have the file contents in sorted order and can do whatever you'd like with them.
Hope this helps!
qsortfunction, or have you not seen this before?