-2
fread()
を呼び出すときに、私はセグメンテーションフォールトを取得し、私はエラーがあるかもしれない場所を把握することはできません。とSegfaultにfread()を使用し
`void charger(Repertoire* parent){
int i;
if (parent == 0){parent = &source;}
FILE* rep_file = fopen("repertoires.bin", "rb");
fread(parent, sizeof(Repertoire), 1, rep_file); //<-------------- here
fclose(rep_file);
//more code...`
参考までに、私の機能charger()
がここに呼ばれている:
`int main(int argc, char* argv[]){
int i, j, path = 0;
source.nom = "/.";
disque = (char*) calloc(32000, sizeof(char));
charger(0);
//more code...`
レパートリー は(ビルダーは、.cファイルに初期化される)ヘッダファイルにここで定義されています
`typedef struct repertoire{
int taille;
int itaille;
char* nom;
struct repertoire* enfants;
int countup;
int icountup;
struct inode* fichiers;
} Repertoire;
Repertoire source;
//more code...`
誰かが助けることができますか?
コードのスニペットはわずかですが、実際にファイルが開かれたことをチェックしていないときに、ファイルを読み取っているときにエラーが発生します。 'fopen'からの戻り値を常にテストします。これは基本的な必要性です。そして、問題を示す[最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)を投稿してください。 –
ああ、私はその時fopenの不適切な使用をしていたようだ。私はreadオプションでfopenを使ってファイルを作成できると思った。これは私の問題を解決します、ありがとう! –