構造の連結リストを作成したのですが、何らかの理由で別のリンクを追加するたびに先頭アドレスが変更されますが、y 先頭アドレスを最初のエントリにしたいです。これは私のコードです:
struct checkPoints *tgh = NULL;
struct checkPoints **linkedlist = &tgh;
struct checkPoints *cp = malloc(sizeof (struct checkPoints));
chPo = fopen(fileName, mode);
if (chPo == NULL) {
printf("Can't find the files.");
exit(1);
} else {
for (i = 0; i < lines; i++) {
fscanf(chPo, "%c %d %d %d:%d\n", &cp->dropOut, &cp->currentPoint, &cp->competitor, &cp->hour, &cp->minute);
cp->next = NULL;
if (*linkedlist == NULL) {
printf("ONCE");
*linkedlist = cp;
} else {
struct checkPoints *new = *linkedlist;
while (new->next != NULL) {
new = new->next;
}
new->next = cp;
}
}
}
fscanf が発生するたびに、ヘッドアドレスが次のアドレスに変更されます。何かアイデアはありますか?
次の行の後、ヘッド アドレスが変更されます。fscanf(chPo, "%c %d %d %d:%d\n", &cp->dropOut, &cp->currentPoint, &cp->competitor, &cp->hour, &cp->minute);
構造は次のとおりです。
struct checkPoints{
char dropOut;
int currentPoint;
int competitor;
int hour;
int minute;
struct checkPoints *next;
};