我遇到了一个问题,我正在尝试创建一个列表,其中inicioC指的是客户端的第一个节点,客户端的每个节点都将有一个称为inicioA的租赁列表。问题是,我不知道如何保存租赁的第一个指针,比如,客户端的第一个节点只保存一次,但每次租赁的第一个节点不会不同吗?
以下是结构:
typedef struct _aluguer
{
    int id, estado, diaI, mesI, anoI, diaE, mesE, anoE;
    struct _aluguer *prox;
}aluguer, *pAluguer;
typedef struct _registo
{
    int nif,nalu;
    char nome[100];
    struct _registo *prox;
    pAluguer *inicioA;
}registo, *pRegisto;这是我用来将文件中的信息提取到列表列表中的代码
pRegisto iniC(pRegisto inicioC, pAluguer inicioA)
{
FILE *c;
int j, nif, nalu, l=0;
char nome[100];
c = fopen("clientes.txt", "r"); // abrir ficheiro
if(c == NULL)
{
    printf("Erro ao abrir ficheiro %s", "clientes.txt");
    exit(0);
}
while(fscanf(c, "%d %d %s", &nif, &nalu, nome) == 3) //format of info
{
    pRegisto novoC = malloc(sizeof(registo));
    if(novoC == NULL)
    {
        printf("erro alocacao memoria\n");
        return inicioC;
    }
    novoC -> prox = NULL;
    pAluguer inicioA = NULL;
    pRegisto aux = inicioC;
    pRegisto p = NULL;
    novoC->nif=nif;
    novoC->nalu=nalu;
    strcpy(novoC->nome, nome);
    while(aux != NULL)
    {
        p = aux;
        aux = aux->prox;
    }
    if( aux == inicioC)
    {
        inicioC=novoC;
    }
    else
    {
        p->prox = novoC;
    }
    for(j=0; j<novoC->nalu; j++) // repeat is equal to the number of rentals
    {
        l++;
        pAluguer novoA = malloc(sizeof(aluguer));
        if(novoA == NULL)
        {
            printf("erro alocacao memoria\n");
            return inicioC;
        }
        novoA -> prox = NULL;
        pAluguer aux = inicioA;
        pAluguer p = NULL;
        fscanf(c, "%d %d", &(novoA->id), &(novoA->estado));
        if(novoA->estado == 0)
        {
            fscanf(c, " %d %d %d", &(novoA->diaI), &(novoA->mesI), &(novoA->anoI));
        }
        else
        {
            fscanf(c, " %d %d %d %d %d %d", &(novoA->diaI), &(novoA->mesI), &(novoA->anoI), &(novoA->diaE), &(novoA->mesE), &(novoA->anoE));
        }
        while(aux != NULL)
        {
            p = aux;
            aux = aux->prox;
        }
        if( aux == inicioA)
        {
            inicioA=novoA;
        }
        else
        {
            p->prox = novoA;
        }
    }
}
fclose(c);
return inicioC;
}https://stackoverflow.com/questions/50727025
复制相似问题