sort a file in c | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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!?

23rd Jan 2020, 11:55 AM
yeganeh
yeganeh - avatar
6 Respuestas
+ 5
Can you share your code ?
23rd Jan 2020, 11:58 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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.
23rd Jan 2020, 12:09 PM
Fermi
Fermi - avatar
+ 1
you know, its not complete! but ,i just want to know, can I sort a file after create it in c or no!?
23rd Jan 2020, 12:02 PM
yeganeh
yeganeh - avatar
+ 1
could youbplease tell me the code of it?!
23rd Jan 2020, 12:10 PM
yeganeh
yeganeh - avatar
+ 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...
23rd Jan 2020, 12:12 PM
unChabon
unChabon - avatar
+ 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.
23rd Jan 2020, 12:17 PM
yeganeh
yeganeh - avatar