I working on this problem and it's beginning to drive me crazy. I need to read from a data file the first line of the file are the dimensions of the array:
2 3
1 2 3
4 5 6
the second and third lines are the values of the matrix. All I can do is get the code to read the first line setting values to the array. Here is what I have:
I have no clue how to make it read the rest of the file. Any help would be awesome. Thanks in advance. -LarryCode:#include <stdio.h> #include <math.h> int main() { int i, j, x, y, m[100], n, z; FILE *infpt; infpt=fopen("data1.dat", "r"); printf("\nAddress of file infpt = %p\n", infpt); for(i=1; i<=1; i++) { fscanf(infpt,"%d %d", &x, &y); printf("Dimensions:%d x %d \n", x, y); } float b[5][5]; //fscanf(infpt,"%d %d", &i, &j); for (i=0; i<x; i++) for (j=0; j<y; j++) //fscanf(infpt, "%d", ...); printf("[%d %d] = %f\n", i, j, b[i][j]); fclose(infpt); }



LinkBack URL
About LinkBacks


