I'm trying to get txt file to 2d array. But some values at the back are missed. I wonder why this happening.
this is txt file's form I want to get
#define MAZE_ROW 11
#define MAZE_COL 22
char maze[MAZE_ROW][MAZE_COL];
int main(){
Get_Maze();
Print_Maze();
}
void Get_Maze(){
FILE *f=fopen("maze.txt","r");
for(int i=0;i<MAZE_ROW;i++){
for(int j=0;j<MAZE_COL;j++){
fscanf(f,"%c",&maze[i][j]);
}
}
fclose(f);
}
void Print_Maze(){
for(int i=0;i<MAZE_ROW;i++){
for(int j=0;j<MAZE_COL;j++){
printf("%c",maze[i][j]);
}
}
}
0|1content.fscanf(f,"%c",&maze[i][j]);will read'\n'too. 황성문, is that what you want? Try"%c"-------->" %c"(add space).