I am stuck in loading letters from text file into 2D array.
my code is like below;;
#include <stdio.h>
int main() {
int i, j, a, b;
char c;
char f, filename[100];
char match[i][j];
FILE *fp;
fp = fopen(filename, "r");
for (a = 0; a < i; a++) {
for (b = 0; b < j; b++) {
match[i][j] = '.';
}
}
while ((c = fgetc(fp)) != EOF) {
for (a = 0; a < i; a++) {
for (b = 0; b < j; b++)
if ((c != '\n') && (c != '\r'))
match[a][b] = c;
}
}
for (a = 0; a < i; a++) {
for (b = 0; b < j; b++)
printf("%c", match[a][b]);
printf("\n");
}
return 0;
}
and text file contains letters like:
AAAAA\nBBBBB\nCCCCC\nDDDDD\nEEEEF\n
I want to load text file to program exactly same, but it is only showing the result
like:
FFFFF\nFFFFF\nFFFFF\nFFFFF\nFFFFF\n
can you please tell me where is the problem?
iandjuninitialized to determine the size ofmatch.i,j, andfilenameare all uninitialized.