簡単なはずの何かであなたの助けが欲しいのですが、なぜそれがうまくいかないのかわかりません. int であることがわかっているビンから最初のデータを読み取りたい。コードの次の部分を使用していますが、セグメンテーション エラーが発生しています。
int main(int argc, char **argv)
{
int *data;
/*opening file*/
FILE *ptr_myfile;
ptr_myfile=fopen(myfile.bin","rb");
if (!ptr_myfile)
{
printf("Unable to open file!\n");
return 1;
}
/*input file opened*/
printf("I will read the first 32-bit number\n");
/*will read the first 32 bit number*/
fread(&data,sizeof(int),1, ptr_myfile);
printf("Data read is: %d\n",*data);
fclose(ptr_myfile);
return 0;
}
また、次のように呼び出してみました。
fread(data,sizeof(int),1, ptr_myfile);
ポインターのあるものである必要がありますが、何がわかりません。