Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Reading data from file
- #define INFO_FILE "savefile.txt" // Definition of our info file
- new info[3], File:myfile; // Our info array and file variable
- if(fexist(INFO_FILE)) // if the file exist
- {
- myfile = fopen(INFO_FILE, io_read); // Let us read from this file
- if(myfile) // If the file has been opened properly
- {
- new buffer[128], bufferlen; // Buffer array (string) and the lenght of the buffer after getting a line from this file
- while(fread(myfile, buffer)) // Iteration methode of reading the whole file
- {
- bufferlen = strlen(buffer); //It's not good using strlen(buffer) inside the loop so..
- for(new i = buferlen-1; i >= 0; i--) if(buffer[i] == '\r' || buffer[i] == '\n') buffer[i] = 0; // Iteration methode removing the next line character for later usage.
- info[i] = strval(buffer); // Storing the value inside an array
- printf("Information %d: Value %d", i+1, info[i]); // Printing the values (debugging)
- }
- }
- else printf("Error at reading the file '%s'", INFO_FILE); // If an error occurs
- }
- else printf("File '%s' doesn't exist.", INFO_FILE); // Otherwise...
Advertisement
Add Comment
Please, Sign In to add comment