Just wondering if there is an easier way like in C++.
This short bit of code opens a file and checks the binary number saved and closes the file. It then converts that number to decimal. Then it checks it against your current score from the end of the game and if it is higher reopens the file and converts that decimal number into binary and saves it to the file.
Is there an easier or even shorter way of doing this. Or is this about it.
void filewrite()
{
highscoreint = 0;
highscore = fopen("falling.sdr", "r");
if (highscore == 0 )
{
highscore = fopen("falling.sdr", "w");
fclose(highscore);
return;
}
i = 0;
while ((x = fgetc(highscore)) != EOF)
{
x -= 48;
BinaryNum[i] = x;
i++;
}
for (i = 15, x = 0; i >= 0; i--, x++)
{
if (BinaryNum[i] == 1)
highscoreint += pow(2, x);
}
textprintf_ex(activepage, font, 250, 240, makecol(0, 0, 0), -1, "High Score: %i", highscoreint);
if (highscoreint < score + totalscore)
flag = 1;
fclose(highscore);
if (flag)
{
highscore = fopen("falling.sdr", "w+");
if ((score + totalscore) > oldhighscoreint)
{
highscoreint = oldhighscoreint;
highscoreint = score + totalscore;
for (i = 15; i >= 0; i--)
{
PlaceHolder = pow(2, i);
if ((highscoreint) >= PlaceHolder)
{
highscoreint -= PlaceHolder;
BinaryNum[i] = 1;
}
else
BinaryNum[i] = 0;
}
}
for (i = 15; i >= 0; i--)
fprintf(highscore, "%i", BinaryNum[i]);
fclose(highscore);
}
}