0

コードの少し複雑なセクションで問題が発生したため、それを取り除きましたが、それでもエラーは残ります。これを大まかに見て、私の間違いを指摘していただけますか?

//before this, nbnoeud is defined and graphe is a stream that reads from a .txt file

double* xtab = (double *) calloc(nbnoeud, sizeof(double));
double* ytab = (double *) calloc(nbnoeud, sizeof(double));
char** nomtab = (char **) calloc(nbnoeud, 100*sizeof(char));

double x, y; char nom[100]; int numero=0, scancheck;

int a;
for(a=0; a<nbnoeud; a++){
    scancheck = fscanf(graphe, "%d %lf %lf %[^\n]", &numero, &x, &y, nom);
    if(scancheck = 4) printf("Read item %d; \t Scancheck: %d; \t %s - (%lf, %lf). \n", numero, scancheck, nom, x, y);
    xtab[a] = x; 
    ytab[a] = y;
    nomtab[a] = nom; I imagine it's something to do with compatibility of this but to my eyes it all checks out
    /*int b; //this section just illustrates that only the previously accessed elements are being overwritten. See code2.png
    for(b=0; b<=nbnoeud; b++){
        printf("%s \n", nomtab[b]);
    }*/
}

for(a=0; a<nbnoeud; a++){
    printf("Read item %d; \t \t \t %s - (%lf, %lf). \n", a, nomtab[a], xtab[a], ytab[a]);
}

exit(1);

すべての値 ( 、 など) が書き込まれた最終値と等しいため、( この場合は )を印刷するnomtab[0]ときに問題が発生します。奇妙なことに、それをチェックしたところ、既にアクセスされた要素のみが上書きされます。たとえば、最初のループの後、残りは equal ; 2 番目のループの後、&と残りは等しい(2 番目の画像を参照)。これには馬鹿げた単純な解決策があると思いますが、それは知らないことをさらに耐え難いものにします.[7]nbnoeud = 8nomtab[0]nomtab[1]nomtabnomtab[0]= Aaanullnomtab[0]nomtab[1] = Baanull

私も使用strcpyしてみましたが、それは好きではありませんでした。

何か案は?

出力:

出力:

各ループ後に配列の内容をチェックして出力

各ループ後に配列の内容をチェックして出力

4

1 に答える 1