/* input a 2D array from a file, then output values from a 2D array to a file */ #include int main() { int i, j; float values[3][4]; FILE *fptr; /* first, input the data */ fptr = fopen("05_input.dat", "r"); for (i=0; i<3; i++) for (j=0; j<4; j++) fscanf(fptr, "%f", &values[i][j]); fclose(fptr); /* now, output the data. Yes, we're reusing 'fptr', but since it's been used and closed, that's allowed */ fptr = fopen("05_output.txt", "w"); /* print out the values */ for (i=0; i<3; i++) { for (j=0; j<4; j++) { fprintf(fptr, "%4.2f ", values[i][j]); } fprintf(fptr, "\n"); } fclose(fptr); }