//============================================================== // Tablica dynamiczna dwuwymiarowa;
// czytanie danych (macierz) z pliku tekstowego;
// przyklad do praktycznego wykorzystania na innych przedmiotach //
// ver data temat autor // 100 2005/10/12 Pierwszy projekt J. Malinowski // 101 2007/11/09 Cleanup JM // 102 2019/12/08 Dodanie opisow JM //============================================================== #include <stdio.h> #include <iostream> using namespace std; //---void toPrint(double *Ar2D[], int m, int n);
//============================================================== #pragma argsused
int main(int argc, char* argv[]) {
/*
char Name[256];
printf("\nName of input file: "); scanf("%s", Name); FILE *pf = fopen(Name, "rt"); */ FILE *pf = fopen("mac_5x3.dat", "rt"); int i,j; int m,n;
fscanf(pf,"%d %d", &m, &n); // Kreowanie tablic dynamicznych; double **M;
M = new double* [m]; for(i=0; i<m; i++)
M[i] = new double [n]; for(i=0; i<m; i++) {
for(j=0; j<n; j++) { fscanf(pf,"%lf",&M[i][j]); } } fclose(pf); toPrint(M, m, n);
// Usuwanie tablic dynamicznych; for(i=0; i<m; i++)
delete [] M[i]; delete M; // system("PAUSE"); return 0; } //============================================================== void toPrint(double *Ar2D[], int m, int n)
{
printf("\nArray( %u x %u )\n\n", m, n); for(int i=0; i<m; i++) {
for(int j=0; j<n; j++) { printf(" %6.1lf", Ar2D[i][j]); } printf("\n"); } } //==============================================================