C에서 FILE * fp를 사용하여 저장된 행렬을 읽는 방법은 무엇입니까? 파일을 읽는 중 문제가 발생했습니다.
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;
}
이
은 내가 읽고 싶은 행렬이다 :1 2 9
3 6 7
4 9 5
혹시 가지고있는 문제에 대해 언급하고 싶습니까? –
출력은 어떻게됩니까? – rtpg