This post has been edited 1 times, last edit by "SD_R3veNG" (May 5th 2008, 9:32am)
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
int scores[10], moves_x, moves_o;
bool wonx, wono;[/CODE
][code]QFile file;
file.setFileName("highscores.txt");
file.open (QIODevice::ReadOnly | QIODevice::Text);
QDataStream in(&file);
for (int count=0; count<10 || !file.atEnd(); count++)
{
in >> (scores[count]);
}
file.close();
if(wonx)
scores[10]=moves_x;
if(wono)
scores[10]=moves_o;
int_qsort(scores, 11); //Call funtion to sort in ascending order
file.open( QIODevice::Truncate | QIODevice::Text | QIODevice::ReadWrite);
QDataStream out(&file);
for (int count=0; count < 10; count++) //I only want 10 highscores saved
out << scores[count] << "\n";
file.close();
|
This post has been edited 1 times, last edit by "jpenguin" (May 6th 2008, 4:52am)
Quoted
Originally posted by jpenguin
Thanks, it looks like it should work; but I can't get it. By default, the file has 10 lines, each with a 9. Heres my code, can you take a look at it
![]()
Source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25int scores[10], moves_x, moves_o; bool wonx, wono;[/CODE ][code]QFile file; file.setFileName("highscores.txt"); file.open (QIODevice::ReadOnly | QIODevice::Text); QDataStream in(&file); for (int count=0; count<10 || !file.atEnd(); count++) { in >> (scores[count]); } file.close(); if(wonx) scores[10]=moves_x; if(wono) scores[10]=moves_o; int_qsort(scores, 11); //Call funtion to sort in ascending order file.open( QIODevice::Truncate | QIODevice::Text | QIODevice::ReadWrite); QDataStream out(&file); for (int count=0; count < 10; count++) //I only want 10 highscores saved out << scores[count] << "\n"; file.close();