Ir ao conteúdo
  • Cadastre-se

Problema ao remover item de lista


Fabio Ramalho

Posts recomendados

Olá pessoal!!

 

Preciso de uma ajuda !

Fiz um código para cadastrar produtos e pedidos. Ambos cadastros eu coloco em LISTAS : produto LISTA e pedido LISTA2.

 

Eu fiz uma função para remoção do cadastro em uma posição dada, porém ele não está funcionando, acredito que está retornando 0.

 

Abaixo segue o código. Se alguém puder me dar uma luz ! hehe

 

Abraços!

 

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>

typedef struct cadastro

    int cod;
    char nome_agulha[30];
    int serie;
    int qtde;
    float preco;
    int forca_mola;
} agulha;

typedef struct pedido
{
    int cod;
    char nome_pedido[30];
    int qtde;
    float preco_pedido;
}venda;

typedef struct LISTA {
    int quant;
    agulha dados[30];
}LISTA;

typedef struct LISTA2 {
    int quant;
    venda dados[30];
}LISTA2;

void entrada_cadastro(LISTA *temp);
void entrada_pedido(LISTA2 *temp);
//void remove_cadastro(LISTA *temp);
int insereInicioL(LISTA *temp, agulha dado);
int insereInicioL2(LISTA2 *temp, venda dado);
int removePosL(LISTA *temp, agulha *dado, int pos);
int removePosL2(LISTA2 *temp, venda *dado, int pos);


int main()
{
    LISTA finfo;
    LISTA2 linfo;
    venda info2;
    agulha info;
    int pos;

    finfo.quant = 0;

    do
    {
        printf("-----------------SUPRATEC LTDA-----------------\n");
        printf("-----CADASTRO INTERNO DE AGULHAS DE TESTE------\n\n");
        printf("DIGITE: \n");
        printf(" 1)INSERIR CADASTRO \n 2)INSERIR PEDIDO\n 3)REMOVER CADASTRO\n 4)REMOVER PEDIDO 5)VER ENTREGAS\n 6)FECHAR SISTEMA\n");
        switch (_getch())
        {
        case'1': entrada_cadastro(&finfo); break;
        case'2': entrada_pedido(&linfo); break;
        case'3': printf("Posicao: ");
                    rewind(stdin);
                    scanf_s("%d", &pos);
                    if (removePosL(&finfo, &info, pos))
                    printf("Cadastro removido com sucesso!");
                    else
                    printf("Erro ao remover\n");
                    break;
                    default: printf("erro\n");
        case'4': printf("Posicao: ");
            rewind(stdin);
            scanf_s("%d", &pos);
            if (removePosL2(&linfo, &info2, pos))
                printf("Pedido removido com sucesso!");
            else
                printf("Erro ao remover\n");
            break;
        }
        _getch();
        system("cls");
    } while (1);

    system("pause");
    return 0;
}

    

    void entrada_cadastro(LISTA *temp)
    {
        int i = 0;
        agulha info[30];
        int op=0;
        int cont=0;
        LISTA p;
        
        do {
            system("cls");
            printf("Escreva a familia \n");
            rewind(stdin);
            fgets(info.nome_agulha, 30, stdin);
            printf("Digite a serie (100, 75 ou 50) \n");
            scanf_s("%d", &info.serie);
            printf("Digite a quantidade: \n");
            scanf_s("%d", &info.qtde);
            printf("Digite o preco: \n");
            scanf_s("%f", &info.preco);
            cont++;
            cont = info.cod;
            if (insereInicioL(&p, info))
                printf("Cadastro realizado com sucesso!\n");
            else
                printf("Erro ao registrar cadastro!\n\n");
            printf("Deseja cadastrar mais um item(1-SIM 2-NAO)?\n");
            scanf_s("%d", &op);
            system("cls");
        } while (op == 1);
    }
    void entrada_pedido(LISTA2 *temp)
    {
        int i=0;
        venda info[30];
        int op = 0;
        int cont = 0;
        LISTA2 p;
        do 
        {
            system("cls");
            printf("Digite o nome da agulha:\n");
            rewind(stdin);
            fgets(info.nome_pedido, 30, stdin);
            printf("Digite a quantidade:\n");
            scanf_s("%d", &info.qtde);
            printf("Digite o valor:\n");
            scanf_s("%f", &info.preco_pedido);
            cont++;
            cont = info.cod;
            if (insereInicioL2(&p, info))
                printf("Pedido inserido na fila de entrega!\n");
            else
                printf("Erro ao registrar pedido!\n\n");
            printf("Deseja cadastrar mais um pedido? (1) SIM (2) NAO\n");
            scanf_s("%d", &op);
            system("cls");
        }   while (op == 1);
    }
    int vaziaL(LISTA *temp)
    {
        if (temp == NULL)
            return -1;
        if (temp->quant == 0)
            return 1;
        else
            return 0;
    }

    int insereInicioL(LISTA *temp, agulha dado)
    {
        if (temp == NULL)
            return 0;
        int aux;
        for (aux = temp->quant; aux > 0; aux--)
        {
            temp->dados[aux+1] = temp->dados[aux];
            temp->dados[aux] = temp->dados[aux - 1];
        }
        temp->dados[0] = dado;
        temp->quant++;
        return 1;
    }

    int insereInicioL2(LISTA2 *temp, venda dado)
    {
        if (temp == NULL)
            return 0;
        int aux;
        for (aux = temp->quant; aux > 0; aux--)
        {
            temp->dados[aux] = temp->dados[aux - 1];
        }
        temp->dados[0] = dado;
        temp->quant++;
        return 1;

    }

    int removePosL(LISTA *temp, agulha *dado, int pos)
    {
        pos--;
        if (temp == NULL)
            return 0;
        if (vaziaL(temp))
            return 0;
        if (pos < 1 || temp->quant <pos)
            return 0;

        *dado = temp->dados[pos];
        int aux;
        for (aux = pos; aux < temp->quant; aux++)
        {
            temp->dados[aux] = temp->dados[aux + 1];
        }

        temp->quant--;
        return 1;
        
    }

    int removePosL2(LISTA2 *temp, venda *dado, int pos)
    {
        pos--;
        if (temp == NULL)
            return 0;
        if (pos < 1 || temp->quant <pos)
            return 0;

        *dado = temp->dados[pos];
        int aux;
        for (aux = pos; aux < temp->quant; aux++)
        {
            temp->dados[aux] = temp->dados[aux + 1];
        }

        temp->quant--;
        return 1;
 

Link para o comentário
Compartilhar em outros sites

  • 2 semanas depois...
Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...