DarthRaff Posted January 4, 2015 Share Posted January 4, 2015 Hello, Happy new year every body!!!! I'm want to load a level from a .dat file, but no succes. This is what i have: . . . nivelActual = 1; . . . void ReadFromFile() { FILE *fichDatos; char nombreFich[50]; sprintf(nombreFich, "nivel%03d.dat", nivelActual);// This line is not working fichDatos = fopen(nombreFich, "rt"); //fichDatos = fopen("nivel1.dat", "rt"); This works, so, the file exists } . . . Can someone tell me what am i doing wrong, please, thank you very much Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 4, 2015 Share Posted January 4, 2015 Perhaps this "nivel%03d.dat shoudl be this: "nivel%i.dat http://www.cplusplus.com/reference/cstdio/printf/ Quote Link to comment Share on other sites More sharing options...
DarthRaff Posted January 4, 2015 Author Share Posted January 4, 2015 Thank you very much, Aggror, it works Quote Link to comment Share on other sites More sharing options...
Ma-Shell Posted January 5, 2015 Share Posted January 5, 2015 Although Aggror already answered the original question here is the reason, why your version didn't work. Your original formatstring said "nivel%03d.dat". The "0" means fill with zeros to the left, so it would have meant "nivel001.dat". For more info on Formatstrings refer to: http://www.cplusplus.com/reference/cstdio/printf/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.