Hi....again
I'm having a little problem with an infinite loop, all works normally except the print function who never stop
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct eng
{
char nomes[100];
char curso[100];
char inst[100];
int nota;
char curri[100];
}INFO;
typedef struct elemento
{
INFO nodo;
struct elemento *seguinte;
struct elemento *anterior;
}ELEM;
int enqueue(INFO info, ELEM **initLista, ELEM **fimLista)
{
ELEM *novo;
novo=(ELEM*)malloc(sizeof(ELEM));
if(novo==NULL)
{
printf("Erro na lista");
return -1;
}
novo->nodo=info;
novo->seguinte=NULL;
novo->anterior=NULL;
if(*initLista==NULL)
{
*initLista=novo;
*fimLista=novo;
}
novo->anterior=novo;
(*fimLista)->seguinte=*fimLista;
*fimLista=novo;
return 0;
}
int print(ELEM *initLista)
{
ELEM *aux;
if(initLista==NULL){
printf("lista vazia!\n");
return -1;
}
aux=initLista;
for(aux=initLista;aux!=NULL;aux=aux->seguinte)
{
printf("%s %s %s %d %s\n",aux->nodo.nomes,aux->nodo.curso,aux->nodo.inst,aux->nodo.nota, aux->nodo.curri);
aux=aux->seguinte;
}
return 0;
}
int listarMaiorCatorze(ELEM *initLista)
{
ELEM *aux;
aux= initLista;
if(aux->nodo.nota>14)
{
printf("%s %d", aux->nodo.nomes,aux->nodo.nota);
aux=aux->seguinte;
}
return 0;
}
int nextOnList(ELEM *initLista)
{
//printf(initLista->seguinte);
return 0;
}
int main()
{
ELEM *initLista=NULL, *fimLista=NULL;
INFO info;
int op;
char buf[30];
do
{
printf("Name: \n");
fgets(info.nomes, 100, stdin);
printf("Degree: \n");
fgets(info.curso, 100, stdin);
printf("Institution: \n");
fgets(info.inst, 100, stdin);
printf("Grade: \n");
fgets(buf, 100, stdin);
sscanf(buf, "%d", &info.nota);
printf("Curriculum: \n");
fgets(info.curri, 100, stdin);
printf("More records? (0-to leave) \n");
scanf("%d", &op);
getchar();
}
while(op!=0);
enqueue(info,&initLista, &fimLista);
print(initLista);
printf("\nCandidatos com mais de 14: \n");
listarMaiorCatorze(initLista);
return 0;
}
The print function works with inifinite loop.
If i want to retrieve the next candidate, what do i have to do??
Regards