WSTI

12d_3

Jan 12th, 2012
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. /*
  7. Zapisać dane z tablicy liczb do pliku a następnie wczytać dane z pliku od jego końca.
  8. */
  9.  
  10. int main()
  11. {
  12.     FILE *file;
  13.     file = fopen ("3.txt","w");
  14.     int tab[] = {1,2,3,4,5,6,7,8};
  15.     int size = sizeof(tab)/sizeof(int);
  16.     int i=0;
  17.  
  18.     while(i<size)
  19.     {  
  20.         fprintf (file, "%i",tab[i]);
  21.         i++;
  22.     }
  23.     fclose(file);
  24.    
  25.     file = fopen ("3.txt","a+");
  26.     fseek(file,0,2);
  27.    
  28.     char c;
  29.    
  30.     for(int i=1;i<size+2;i++)
  31.     {
  32.         c=fgetc(file);
  33.         cout << c;
  34.         fseek(file,-i,2);
  35.     }
  36.    
  37.     fclose(file);
  38.    
  39.    
  40.     getch();    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment