Jump to content
Fórum Script Brasil
  • 0

programa veiculos


thematrix

Question

olá amigos estou fazendo um algoritmos para cadastrar,buscar, e alterar, nomes, modelo de carro, placa, combustivel, ano e etc, já esta praticamente feito, so que tem um pequeno probleminha, na função busca tenho uma opção de menu pra listar os carros com placa que iniciam com a letra 'a' e tenham o final 02 ou 47, consegui fazer a função perfeitamente, mas se cadastro 2 carros com a mesma condição de placa, ele apenas lista o primeiro carro, a variavel compara não recebe a proxima placa indicada pelo ponteiro, peço ajuda ;D

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
void insere();
void wait();
void busca();
void alterar();
void lista_d();
struct cadastro{
    char nome[256];
    char modelo[256];
    char n_chassi[256];
    int ano;
    char placa[256];
    char cor[256];
    char gas[256];
    cadastro *prox;
}*Cab, *fim;
main()
{
    Cab = fim = NULL;
    int op;

    printf("################DETRAN##############\n");
    while(op != 4){
        printf("1 - cadastrar\n");
        printf("2 - buscar\n");
        printf("3 - alterar\n");
        printf("4 - sair\n");
        printf(">");
        scanf("%d",&op);
        system("clear");
        switch(op)
        {
            case 1:
                insere();
                system("clear");
                break;
            case 2:
                busca();
                system("clear");
                break;
            case 3:
                alterar();
                system("clear");
                break;
            case 4:
                exit(0);
                break;
        }


    }
}


void busca()
{
    int opcao;
    cadastro *p2;
    while(opcao!= 3)
    {
        system("clear");
        printf("O que deseja fazer?\n");
        printf("1 - Listar todos cadastros\n");
        printf("2 - listar\n");
        printf("3 - Voltar ao menu principal\n");
        scanf("%d",&opcao);
        switch(opcao)
        {
            case 1:
                p2 = Cab;
                printf("\nCADASTRADOS\n");
                printf("----------------------------------\n\n");
                while(p2 != NULL)
                {
                    printf("NOME: %s\nMODELO: %s\nPLACA: %s\n Chassi: %s\n COR: %s\nCOMBUSTIVEL: %s\nANO: %d\n",p2->nome,p2->modelo,p2->placa,p2->n_chassi,p2->cor,p2->gas,p2->ano);
                    printf("----------------------------------\n");
                    p2 = p2->prox;
                }
                wait();
                break;
            case 2:
                p2 = Cab;
                int opcao1;
                int x,busca2;
                char busca[256];
                printf("1 - Buscar pelo Nome\n");
                printf("2 - Buscar pelo Modelo\n");
                printf("3 - Buscar pela Placa\n");
                printf("4 - Buscar ANO 1980 a disel\n");
                printf("5 - Listar placas 'A' final 02|47\n");
                printf("6 - Voltar\n");
                scanf("%d",&opcao1);
                if(opcao1 == 6) break;
                if(opcao1 == 1)
                {
                    wait();
                    x = 0;
                    printf("Digite o nome que deseja procurar: ");
                    fgets(busca,255,stdin);
                    while(p2 != NULL)
                    {
                        if(!strcmp(p2->nome,busca))
                        {
                            printf("NOME: %s\nMODELO: %s\nPLACA: %s\n Chassi: %s\n COR: %s\nCOMBUSTIVEL: %s\nANO: %d\n",p2->nome,p2->modelo,p2->placa,p2->n_chassi,p2->cor,p2->gas,p2->ano);
                            printf("----------------------------------\n");
                            p2 = p2->prox;
                            x = 1;
                        }
                        else
                        {
                            p2 = p2->prox;
                        }
                    }
                    if(x==0)
                    {
                        printf("Nenhum Cadastro encontrado!\n");
                        wait();
                        break;
                    }
                    else
                    {
                        wait();
                        break;
                    }
                }
                else if(opcao1 == 2)
                {
                    wait();
                    x = 0;
                    printf("Digite o modelo:");
                    fgets(busca,255,stdin);
                    while(p2 != NULL)
                    {
                        if(!strcmp(p2->modelo,busca))
                        {
                            printf("NOME: %s\nMODELO: %s\nPLACA: %s\n Chassi: %s\n COR: %s\nCOMBUSTIVEL: %s\nANO: %d\n",p2->nome,p2->modelo,p2->placa,p2->n_chassi,p2->cor,p2->gas,p2->ano);
                            printf("----------------------------------\n");
                            p2 = p2->prox;
                            x = 1;
                        }
                        else
                        {
                            p2 = p2->prox;
                        }
                    }
                    if(x==0)
                    {
                        printf("Nenhum cadastro encontrado!\n");
                        wait();
                        break;
                    }
                    else
                    {
                        wait();
                        break;
                    }
                }
                else if(opcao1 == 3)
                {
                    wait();
                    x = 0;
                    printf("Digite uma placa para pesquisar: ");
                    fgets(busca,255,stdin);
                    while(p2 != NULL)
                    {
                        if(!strcmp(p2->placa,busca))
                        {
                            printf("NOME: %s\nMODELO: %s\nPLACA: %s\n Chassi: %s\n COR: %s\nCOMBUSTIVEL: %s\nANO: %d\n",p2->nome,p2->modelo,p2->placa,p2->n_chassi,p2->cor,p2->gas,p2->ano);
                            printf("----------------------------------\n");
                            p2 = p2->prox;
                            x = 1;
                        }
                        else
                        {
                            p2 = p2->prox;
                        }
                    }
                    if(x==0)
                    {
                        printf("Nenhum cadastro encontrado!\n");
                        wait();
                        break;
                    }
                    else
                    {
                        wait();
                        break;
                    }
                }
                else if(opcao1 == 4)
                {
                    wait();
                    x = 0;
                    printf("digite o combustivel:");
                    fgets(busca,255,stdin);
                    busca2 = 1980;
                    while(p2 != NULL)
                    {
                        if(!strcmp(busca,p2->gas) && busca2 <= p2->ano)
                        {
                            printf("NOME: %s\nPLACA:%s\n",p2->nome,p2->placa);
                            printf("----------------------------------\n");
                            p2 = p2->prox;
                            x = 1;
                        }
                        else
                        {
                            p2 = p2->prox;
                        }
                    }
                    if(x==0)
                    {
                        printf("Nenhum cadastro encontrado!\n");
                        wait();
                        break;
                    }
                    else
                    {
                        wait();
                        break;
                    }
                }
                else if(opcao1 == 5)
                {
                    wait();
                    x = 0;
                    char letra = 'a';
                    char temp[255];
                    int conta,i=0,j=0;
                    char *compara;
                    compara = temp;
                    conta = strlen(p2->placa);
                    while(p2 != NULL)
                    {
                        for(i=0;i<conta;i++){
                            compara[j++] = p2->placa[i];
                            compara[j]  = '';
                        }
                        if(compara[0] == letra && compara[5]=='0' && compara[6]=='2' || compara[5] == '4' && compara[6] == '7')
                        {
                            printf("NOME: %s\nMODELO: %s\nPLACA: %s\n Chassi: %s\n COR: %s\nCOMBUSTIVEL: %s\nANO: %d\n",p2->nome,p2->modelo,p2->placa,p2->n_chassi,p2->cor,p2->gas,p2->ano);
                            printf("----------------------------------\n");
                            printf("compara = %s , conta = %d\n",compara,i);
                            p2 = p2->prox;
                            x = 1;
                        }

                        else
                        {
                            p2 = p2->prox;
                        }
                        
                    if(x==0)
                    {
                        printf("Nenhum cadastro encontrado!\n");
                        wait();
                        break;
                    }

                    else
                    {
                        wait();
                        break;
                    }



                }
                }

                break;
            case 6:
                break;
            default:
                printf("Opcao não existe\n");
                wait();
        }
    }
}

listei apenas a função busca e o programa main para analizarem, so estou na duvida da opcao==5 mesmo, e desculpe mas não consegui colocar o codigo no codebox.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...