I have a text file (H.txt) that looks something like this:
1 0 1 1 0 1
0 0 1 1 0 0
0 0 0 1 0 0
1 1 1 0 0 0
I need to read this text file into a 2D array called H. The size of the text file can change in length and width (i.e.. there can be more rows and more columns of binary data than the example I have above).
Heres what I have so far:
#import <stdio.h>
int main()
{
int m = 4;
int n = 6;
int H[m][n];
FILE *ptr_file;
char buf[1000];
ptr_file = fopen("H.txt", "r");
if (!ptr_file)
return 1;
fscanf(ptr_file,"%d",H);
fclose(ptr_file);
return 0;
}
Any help would be appreciated.