Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //lettura matrice da file,scambiare le riga con colonne e rimetterla in file con percorso inserito da tastiera
- #include<iostream>
- #include<fstream>
- #include<iomanip>
- using namespace std;
- #define card 100
- char percorso1[card];
- char percorso2[card];
- using namespace std;
- typedef int tmatrice[card][card];
- tmatrice matrice;
- fstream file1,file2;
- void lettura_matrice_da_file(fstream &file1,int matrice[][card],int rr,int rc,char percorso1[]);
- void stampa_scambio_matrice(int matrice[][card],int rr,int rc);
- void scrittura_su_file(fstream &file2,int matrice[][card],int rr,int rc,char percorso2[]);
- int rr;
- int rc;
- int main()
- {
- lettura_matrice_da_file(file1,matrice,rr,rc,percorso1);
- stampa_scambio_matrice(matrice,rr,rc);
- scrittura_su_file(file2,matrice,rr,rc,percorso2);
- system("pause");
- }
- void lettura_matrice_da_file(fstream &file1, int matrice[][card],int rr,int rc,char percorso1[])
- {
- cout<<setw(2)<<"Inserisci percorso del file";
- cin.getline(percorso1,card-1,'\n');
- file1.open(percorso1,ios::in);
- //gestione errori
- if(!file1)
- {
- cout<<"Impossibile aprire il file";
- exit(1);
- }
- while(!file1.eof())
- {
- file1>>rr;
- file2>>rc;
- for(int i=0;i<rr;i++)
- {
- for(int j=0;j<rc;j++)
- {
- file1>>matrice[i][j];
- }
- }
- }
- file1.close();
- }
- void stampa_scambio_matrice(int matrice[][card],int rr,int rc)
- {
- for(int i=0;i<rr;i++)
- {
- for(int j=0;j<rc;j++)
- {
- cout<<matrice[j][i];
- }
- cout<<endl;
- }
- }
- void scrittura_su_file(fstream &file2,int matrice[][card],int rr,int rc,char percorso2[])
- {
- cout<<setw(2)<<"Inserire percorso in cui si vuole inserire la matrice";
- cin.getline(percorso2,card-1,'\n');
- file2.open(percorso2,ios::out);
- for(int i=0;i<rr;i++)
- {
- for(int j=0;j<rc;j++)
- {
- file2<<matrice[j][i];
- }
- }
- }
Add Comment
Please, Sign In to add comment