I want to copy the content of a file that has a 10 by 10 array of characters to a 2D array. I verified but the compiler gives me an empty screen. The file is opening since the program dosen't print: "error in opening file", i would appreciate it if you help me. This is my code:
#include<stdio.h>
#include<string.h>
int main()
{
char puzzle[10][10], line[10];
int i,j, rows=0;
FILE *fp;
fp=fopen("arr.txt", "r");
if (fp== NULL) {
printf("Error in opening file\n");
return 1;
}
while(!EOF)
{
if(fgets(line, 10, fp) != NULL){
for(i=0; i<(strlen(line)-1); i++)
puzzle[rows][i] = line[i];
}
rows++;
}
for(i=0; i<10; i++)
for(j=0; j<10; j++)
printf("%c", puzzle[i][j]);
}
Thank you