I am new to C programming and need your help... i have a text file which
holds records of the following nature
Thus the file looks something like
I am trying to sort the file on membership number but am not sure what to do!!
I know about various different sorting algorithms and thought i'd use a quicksort or bubblesort in my program... but the thing is i am having trouble moving through the records in the file...
i thought about using the fseek()to move the file pointer to membership number in the first record... then read this into a variable.. then move file pointer to membership number in 2nd record and read.... compare .. if neccesary swap...
Would this method work??? or is there something better i can do without using fseek() as it is hard to keep track of positions in the file
If the file is not too big (less than 100MB) then read all the file into memory, sort it and then write it back to the file.
If there is much more data than that then use some RDBMS to store the data instead of plain text file.
Do not use buble sort for more than a few hundreds of elements. It is extremely slow. Use quick sort.
[ back to toc ]