Advertisement
Guest User

Untitled

a guest
Jun 12th, 2020
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int mat[3][3];
  5.  
  6. int main()
  7. {
  8.     int x, y; //Contatori
  9.     FILE *f; //File
  10.     char directory[50]; //Directory matrice.dat
  11.     char num[2]; //Numero letto da matrice.dat
  12.    
  13.     cout<<"Inserisci directory: ";
  14.     cin>>directory; //Inserisci directory
  15.    
  16.     f = fopen(directory, "rb"); //Apri file
  17.    
  18.     if(f!=NULL) //File aperto
  19.     {
  20.         for(x=0; x<3; x++)
  21.         {
  22.             y = 0;
  23.             cout<<endl;
  24.             while(y<=2)
  25.             {
  26.                 fread(num, sizeof(num), 1, f);
  27.                 if(num!=" ")
  28.                 {
  29.                     mat[x][y] = int(num-'0');
  30.                     y++;
  31.                 }
  32.             }
  33.         }
  34.     }
  35.     else
  36.         cout<<"Errore!\n";
  37.    
  38.     //Stampa matrice
  39.     for(x=0; x<3; x++)
  40.     {
  41.         cout<<endl;
  42.         for(y=0; y<3; y++)
  43.             cout<<mat[x][y]<<'\t';
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement