hey there
i need to convert data from a certain file into a matrix, in order to that matrix be a "labirinth" (i'm working on a project that trys to simulate a labirinth game)
my objective here is to read a file, get his content, and then pass it to a matrix that i have denominated as "char * * matrix;"
so, i'm gonna show you my code so you can understand better:
Code:
void main(){
int c;
fp = fopen(mapa,"r");
if (fp == NULL){
printf("Can't open %s\n",mapa);
exit(0);
}
c = getc(fp);
while(c != EOF ){
putchar(c);
c = getc(fp);
}
now, someone told me that i should do this:
Code:
matrix = (char **)malloc(nr_lines * sizeof(char*));
for (line = 0; line < lines; line++){
matriz[line] = (char*)malloc(nr_columns * sizeof(char*));
} // don't worry, i've already denominated lines, columns etc
so, after this, if this 2nd code is right, my matrix positions (x / y) will be the same as the file i've read?
if not, what better way should i do??
thanks in advance,
i really would appreciate it