BigETI

Save data into file tutorial

Apr 13th, 2012
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.59 KB | None | 0 0
  1. //saving data into a file
  2.  
  3. #define INFO_FILE   "savefile.txt"
  4. new info[3] = {10, 20, 55}, File:myfile = fopen(INFO_FILE, io_write); // An array with integer data and our file variable
  5. if(myfile) // If file exist
  6. {
  7.     for(new i = 0; i < 3; i++) // Iteration methode of getting the data from info array
  8.     {
  9.         new fstr[12]; //array (used as string)
  10.         format(fstr, sizeof fstr, "%d", info[i]); //Formating the string...
  11.         fwrite(myfile, fstr); // Writing the formated stuff into the file
  12.     }
  13.     fclose(myfile); // Closing our file
  14. }
  15. else printf("Couldn't open file '%s'.", INFO_FILE); // Otherwise...
Advertisement
Add Comment
Please, Sign In to add comment