我遇到了一个问题,我想把项目添加到链接列表的末尾,但似乎我被卷入了一个无限循环中。

void addCheckPoint(struct checkPoints **checkPoint) {
    struct checkPoints *checkPt = *checkPoint;

    while (checkPt->next != NULL) {
        checkPt->next;
        if (checkPt->next == NULL) {
            scanf("%c %d %d %d %d", &checkPt->dropOut, &checkPt->currentPoint, &checkPt->competitor, &checkPt->hour, &checkPt->minute);
        }
    }
}

最佳答案

void addCheckPoint(struct checkPoints **checkPoint) {
    struct checkPoints *checkPt = *checkPoint;

    while (checkPt != NULL) {
        if (checkPt->next == NULL) {
            scanf("%c %d %d %d %d", checkPt->dropOut, checkPt->currentPoint, checkPt->competitor, checkPt->hour, checkPt->minute);
        }
        checkPt = checkPt->next;
    }
}

09-26 06:49