Delete data in chained dynamic list using C language

Asked

Viewed 186 times

0

Good afternoon. I’m doing a project for the college where the teacher asked to create an algorithm with dynamic lists, where one list should contain customers and another, products. The goal of the project is to make the CRUD of both lists, on the condition that the customer cannot be excluded if he has any product attached to it. The rest of the algorithm I managed to do, but I stopped at deletion. Could you help me? Since the code is kind of big (about 600 lines), I put it in Git instead of posting it in text here.

https://github.com/GabrielManiza/structured

I really appreciate the patience and all the help you can give me!


EDITION: The part that is giving me problems is how to check if the customer has products. I need to delete it if you don’t have it and keep it (showing an error message) if there are related products. In my code, the function that is responsible for this (and not working) is:

struct listacliente* remove_ordenado(struct listacliente *inicio, int x)
{
    struct listacliente *p,*q;
    p = inicio;
    q = inicio;

    while(p != NULL)
    {
        if (p->info.codigo != x)
            p = p->proximo;

        else if(p->prod != NULL)
                {
                    printf("O cliente tem produtos cadastrados e não pode ser removido.\nPor favor, remova todos os produtos e então tente novamente.");
                    break;
                }
            else
            {
                inicio = removeInicio(inicio);
                return inicio; 
            }
    }

    if (p == NULL)
        printf("\nCliente não encontrado!");
  • It can bring here only part that is a problem and that can be reproduced. It can make a [mcve].

  • Edited question. If you think it’s wide enough, just say so, but I think reading the code on Github makes it easier to understand the problem. Thank you for the reply!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.