I’ll help you from that response channel, okay?
You commented that you have an error on line 178 of your code.
Your problem is not updating the value of aux, ie your while-statement never stops because aux never exchanges value. The idea would be the following:
while(aux != NULL) {
if(cod_aluno == aux->aluno.codigo) {
if(aux->inicLivro != NULL)
inicio = removeOrdenado(inicio, cod_aluno);
else
printf("O aluno não pode ser removido, pois possui livros em sua conta.");
}
else
aux = aux->proximo;
}
Now, reading the bug reported on line 222, you go through the list, and even if you think, you update aux, which doesn’t need to be done, you should use an if/Else. The "Cot" variable is dispensable, and your final IF is never printed because if you didn’t find that code, the value of aux is NULL.
The code should be:
struct listaAluno *aux;
int cod_aluno;
aux = inicio;
if(aux == NULL)
{
printf("Não há alunos cadastrados no sistema.");
printf("\nImpossivel realizar consulta.");
}
else
{
printf("\nLocalizar Aluno\n");
printf("Informe o código do aluno: ");
scanf("%i", &cod_aluno);
while(aux != NULL)
{
if(cod_aluno == aux->aluno.codigo)
{
printf("\nCódigo: %d | Nome: %s | Curso: %s", aux->aluno.codigo, aux->aluno.nome, aux->aluno.curso);
}
else
aux = aux->proximo;
}
}
if(aux == NULL)
{
printf("O código informado não pertece a nenhum aluno cadastrado no sistema.");
}
And well, as for the problem of the chained list within another chained list, I’ve worked with that already in some labs, and I haven’t followed your idea of structures. You set up four structs, two for lists and two for us.
The way I learned and did very well doing uses only the nodes, and to increase the efficiency of the list uses the technique of nodes "dummy", are nodes that have no function and are the first on the list, and serve, for example, to facilitate removals and insertions the first time they occur.
(I recommend reading: https://www.ime.usp.br/~pf/algorithms/classes/list.html)
Also, as you want to work with removals and inserts at the beginning and end, I suggest using a control struct, which contains the start and end positions of the list.
Thus, in pseudocode, the structures would be:
struct Aluno {
informações do aluno;
ponteiro para o próximo aluno;
ponteiro para sua lista de livros;
}
struct Livro {
informações do livro;
ponteiro para o próximo livro;
}
struct Controle {
informações da lista (quantidade de nós, entre outros); //opcional
ponteiro para o início da lista;
ponteiro para o fim da lista;
}
I wanted to comment on your publication, but I don’t have enough reputation. So this isn’t an answer, I just want to understand your question. You have a chain list of students, right? And each student is related to some books. And each student will be connected to a chained list of books, that’s it?
– Gabriel Pellegrino
Exactly that Gabriel, I just added an image to better convey this idea.
– Gustavo