C dilinde FILE * fp kullanılarak kaydedilen bir matris nasıl okunur? dosyaları okumak için sorun
int main()
{
int i,j;
FILE *fp;
int **mat; //matriz de cartas apartir do arquivo
int n; //numero de jogadores
mat=(char**)malloc(3*sizeof(char*));
for(i=0;i<2;i++){
mat[i]=(char*)malloc(3*sizeof(char));
if(!mat){
printf("erro de alocacao\n");
exit(1);
}
}
fp=fopen("arquivo","r"); //this is the file to read
if(fp==NULL){
printf("erro de abertura de ficheiro\n");
exit(1);
}
for(i=0;i<3;i++){
for(j=0;j<3;j++){
fscanf(fp,"%d",&mat[i][j]);
}
printf("%d\n",mat[i][j]); //problem here
}
return 0;
}
Bu
okumak istiyorum matristir:1 2 9
3 6 7
4 9 5
Muhtemelen sahip olduğunuz problemden bahsetmek ister misiniz? –
hangi çıktı elde edersiniz? – rtpg