I have a text file of size 8 by 12 (8 rows, 12 columns) (x,y)
abcdefghjikl
123456789abc
aerereghjikl
123456789abc
abc43434dfdf
12erere789ab
abcdefghjikl
12345fdfd89a
I'm trying to read each individual character into a 2d array, where the first dimension is the rows, and the second is the columns.
This is what I've tried:
int main(void) {
FILE * fp;
fp = fopen("test.txt","r");
char points[8][12];
int i,j;
for(i=0; i<8; i++) {
for(j=0; j<12; j++) {
fscanf(fp,"%c",&points[i][j]);
}
}
for(i=0; i<8; i++) {
for(j=0; j<12; j++) {
printf("%c",points[i][j]);
}
}
return 0;
}
However my output seems to work correctly, up untill the last line of the file.
abcdefghjikl
123456789abc
aerereghjikl
123456789abc
abc43434dfdf
12erere789ab
abcdefghjikl
12345
Where the last line doesn't fully work. I've tried increasing the array dimensions of the row, which makes the last line appear, but adds garbage values to my output. Any help would be much appreciated.
\nat each line which your putting in your array as well.fopen(),fscanf()...\nusingfseekat the end of the execution of the inner loop.