这是我的模式txt:
##########
#1 # #
# # #
# # #
# #
# #
# #2 ##
# #
# # #
##########
我想在二维数组中逐行加载,如char board [10] [10];
这是我的loadFile代码:
FILE *fp;
fp = fopen(file_name,"r");
do{
for(int a=0;a<10;a++){
for(int b=0;b<10;b++){
fscanf(fp,"%c",&board[a][b]);
}
}
}while(!feof(fp));
// test print for showing into console
for(int c=0;c<10;c++){
for(int d=0;d<10;d++){
printf("%s",board[c][d]);
}
printf("\n");
}
fclose(fp);
答案 0 :(得分:0)
FILE *fp;
fp = fopen(file_name,"r");
for(int a=0;a<10;a++){
for(int b=0;b<10;b++){
fscanf(fp,"%c", &board[a][b]);
}
fscanf(fp, "%*c");//for skip newline
}
fclose(fp);
// test print
for(int c=0;c<10;c++){
for(int d=0;d<10;d++){
printf("%c", board[c][d]);
}
printf("\n");
}