0 Members and 1 Guest are viewing this topic.
That's because i need to write a integer to a file but fscanf() is not available in Ndless...fgetc() works but only writes a char...
QuoteThat's because i need to write a integer to a file but fscanf() is not available in Ndless...fgetc() works but only writes a char...Just choose an endianness for your serialization of integers, and use fgetc on the integer shifted by 8, 16 and 24 then and'ed with 0xFF
yaaaaaaaaay Also, can you still kill the black clouds if you hit 'em right at the end? (and giving more points)
You code fast
Also why is the max points 25500?
sc = (highscore / 10000) % 10; dscore[0]=sc; sc = (highscore / 1000) % 10; dscore[1]=sc; sc = (highscore / 100) % 10; dscore[2]=sc; sc = (highscore / 10) % 10; dscore[3]=sc; sc = highscore % 10; dscore[4]=sc; file = fopen("/documents/rdsave.save.tns", "w+"); fputc( dscore[0], file); fputc( dscore[1], file); fputc( dscore[2], file); fputc( dscore[3], file); fputc( dscore[4], file); fclose(file);
uint32_t ReadLongBigEndian (void) { uint32_t temp_long; temp_long = fgetc(output) << 24; temp_long |= fgetc(output) << 16; temp_long |= fgetc(output) << 8; temp_long |= fgetc(output); return temp_long;}uint32_t ReadLongLittleEndian (void) { uint32_t temp_long; temp_long = fgetc(output); temp_long |= fgetc(output) << 8; temp_long |= fgetc(output) << 16; temp_long |= fgetc(output) << 24; return temp_long;}void WriteIntBigEndian (uint32_t long_in) { fputc (((int)(long_in >> 24)) & 0xFF, output); fputc (((int)(long_in >> 16)) & 0xFF, output); fputc (((int)(long_in >> 8)) & 0xFF, output); fputc (((int)(long_in )) & 0xFF, output); fflush(output);}void WriteIntLittleEndian (uint32_t long_in) { fputc (((int)(long_in )) & 0xFF, output); fputc (((int)(long_in >> 8)) & 0xFF, output); fputc (((int)(long_in >> 16)) & 0xFF, output); fputc (((int)(long_in >> 24)) & 0xFF, output); fflush(output);}
Also, another piece of general advice: don't put .tns files at the root of /documents, because TILP cannot cope with them, which means that users couldn't backup such files once your program has created them.
What I meant was really shifts and ands, not division and modulo on a processor without a divide instruction Code: [Select]uint32_t ReadLongBigEndian (void) { uint32_t temp_long; temp_long = fgetc(output) << 24; temp_long |= fgetc(output) << 16; temp_long |= fgetc(output) << 8; temp_long |= fgetc(output); return temp_long;}uint32_t ReadLongLittleEndian (void) { uint32_t temp_long; temp_long = fgetc(output); temp_long |= fgetc(output) << 8; temp_long |= fgetc(output) << 16; temp_long |= fgetc(output) << 24; return temp_long;}void WriteIntBigEndian (uint32_t long_in) { fputc (((int)(long_in >> 24)) & 0xFF, output); fputc (((int)(long_in >> 16)) & 0xFF, output); fputc (((int)(long_in >> 8)) & 0xFF, output); fputc (((int)(long_in )) & 0xFF, output); fflush(output);}void WriteIntLittleEndian (uint32_t long_in) { fputc (((int)(long_in )) & 0xFF, output); fputc (((int)(long_in >> 8)) & 0xFF, output); fputc (((int)(long_in >> 16)) & 0xFF, output); fputc (((int)(long_in >> 24)) & 0xFF, output); fflush(output);}