+ 1
sort a file in c
hi , Im new in programing, I write a game and now i need to sort a file that has the name and level and score of who are playig up to now, but I cant do it well. wuold you help me please!?
6 Answers
+ 5
Can you share your code ?
+ 4
... Of course you can. Why not. Just read the file contents into their corresponding arrays, sort those arrays, then rewrite the array contents to the file.
+ 1
you know, its not complete!
but ,i just want to know, can I sort a file after create it in c or no!?
+ 1
could youbplease tell me the code of it?!
+ 1
Yes, of course you can.
If you don't have tons of players, read the records into memory (a list, an array, etc.)
Sort it (bubble sort, insertion sort, qsort) and then rewrite the file with the sorted list.
Other methods: use sqlite, use a second file as index and work with it instead of reading the whole data into memory, etc. etc.
google "sort file c" for other options...
+ 1
I now what you mean,
and i do it, I search in a google alot about sort a file, but all of them was befor creating a file!
but you know , in a game i crat a file and save all information in file, after that when a player wants to saw the scores, the scores should sorted and after show to the player.