Tuesday 15 September 2015

C - load txt content into two dimentional array -



C - load txt content into two dimentional array -

this pattern txt:

########## #1 # # # # # # # # # # # # # #2 ## # # # # # ##########

i wanna load line line within two-dimentional array, char board[10][10];

this loadfile code:

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 showing console for(int c=0;c<10;c++){ for(int d=0;d<10;d++){ printf("%s",board[c][d]); } printf("\n"); } fclose(fp);

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"); }

c arrays file io

No comments:

Post a Comment