I have to read a txt file which has the first line to describe the problem. It can be either a or b, then I have some ints and as matrix. My program works for both, but there are files that after the first problem may have another with the same format. I don't know how to do this.
sample of txt:
5 5 A(B) 1
0 3 (start point)´
1 5 6 5 9
5 8 6 3 1
8 6 9 5 3
5 6 9 3 0
2 3 9 3 8
then another problem, or more, with this format
while(!feof(fp)){
fscanf(fp, "%d %d %c %d", &L, &C, &variante, &pontos);
mapa=(int **)malloc(L*sizeof(int*));
for(i=0; i<L; i++){
mapa[i]=(int*)malloc(C*sizeof(int));
}
for(i=0; i<L; i++){
for(j=0; j<C; j++){
mapa[i][j]=0;
}
}
if(variante == 'A') {
fscanf(fp, "%d %d", &Linit, &cinit);
for(i=0; i<L; i++){
for(j=0; j<C; j++){
fscanf(fp, "%d", &mapa[i][j]);
printf("%d-", mapa[i][j]);
}
printf("\n");
}
possivel=varianteA(mapa, L, C, Linit, cinit, &custo);
printf("%d\n",custo);
}
if(variante== 'B'){
line=(int*)malloc(pontos*sizeof(int));
col=(int*)malloc(pontos*sizeof(int));
for(k=0; k<pontos; k++){
line[k]=0;
col[k]=0;
}
for(k=0; k<pontos; k++){
fscanf(fp, "%d %d", &line[k], &col[k]);
}
for(i=0; i<L; i++){
for(j=0; j<C; j++){
fscanf(fp, "%d", &mapa[i][j]);
printf("%d-", mapa[i][j]);
}
printf("\n");
}
possivel=varianteB(mapa, L, C, &custo, pontos, line, col);
printf("%d %d\n", possivel, custo);
free(line);
free(col);
}
for(i=0; i<L; i++){
int *linha;
linha=mapa[i];
free(linha);
}
free(mapa);
}
// free(variante);
fclose(fp);
now I have this, but it does one more problem that is not in the file. and valgrind gives me an error in: possivel=varianteA(..). It says that address is 0 bytes after block of size 24 alloc'd