I have two lists in C, where you have to include several records in the list of customers, and then have some customer able to reserve a car that is stored in the list of cars. The part of inclusion, removal and visualization of customers I can do good, the problem is when it is time for the customer to book a car, ie the cell with the customer's name pointing to the list with the name of the reserved car .
struct carro
{
int codigo;
char modelo[30];
struct carro *proximo;
};
struct cliente
{
int codigo;
char nome[50];
struct cliente *proximo;
struct carro *reserva;
};
// Inserir no inicio da lista;
struct cliente* insereInicio(struct cliente *pInicio,int codigo, char nome[50]){
struct cliente *aux;
aux = (struct cliente *)malloc(sizeof(struct cliente));
aux->codigo = codigo;
strcpy(aux->nome,nome);
aux->proximo = pInicio;
pInicio = aux;
return pInicio;
}
void insereDepois(struct cliente *p, int codigo, char nome[50])
{
struct cliente *aux;
aux= (struct cliente *) malloc(sizeof(struct cliente));
aux ->codigo=codigo;
strcpy(aux->nome,nome);
aux ->proximo=p->proximo;
p->proximo=aux;
}
struct cliente* insereOrdenado(struct cliente *pInicio, int codigo, char nome[50]){
struct cliente *p, *q;
if(pInicio == NULL || codigo < pInicio->codigo){
return (insereInicio(pInicio, codigo, nome));
}
p = pInicio;
q = p;
while(q != NULL && q->codigo > codigo){
p = q;
q = p->proximo;
}
if(q == NULL || q->codigo < codigo){
insereDepois(p,codigo,nome);
}
else{
printf("\nElemento ja existe");
}
return (pInicio);
}
main()
{
struct ciiente *inicio;
inicio = NULL;
int opcao = 0;
int codigo;
char nome[50];
while(1)
{
system("cls");
printf("-----# Bem Vindo #-----\n");
printf("\n1 - Incluir Cliente");
printf("\n2 - Listar clientes");
printf("\n3 - Sair do Programa\n");
scanf("%d",&opcao);
if(opcao == 1) {
system("cls");
printf("-----# Inserir novo Cliente #-----\n");
printf("\nDigite o codigo do cliente: ");
scanf("%d",&codigo);
printf("Digite o nome do Cliente: ");
fflush(stdin);
scanf("%s",nome);
inicio = insereOrdenado(inicio, codigo, nome);
}
else if(opcao == 2)
{
system("cls");
printf("-----# Clientes Cadastrados #-----\n");
percorreLista(inicio);
}
else if(opcao == 3)
{
break;
}
}
My problem is that I have no clue how to get my list of customers to point to a certain node in my list of cars, so I would like to know if anyone could guide me how to do this exactly.
NOTE: I am new to C.