0
I’m trying to make a linear list with chained allocation in C and I’m falling into an infinite loop.
void busca(Lista L, int x, No* ant, No* pont){
No ptr;
*pont = NULL;
*ant = L->ptLista;
ptr = (*ant)->prox;
while (ptr != NULL){
if (ptr->valor < x){
*ant = ptr;
ptr = ptr->prox;
}else{
if(ptr->valor == x){
*pont = ptr;
printf("Numero encontrado\n");
}
ptr == NULL;
printf("Saindo\n");
}
}}
(No = typedef struct no* No) (List = typedef struct list* List) This function does a search for the integer X. However, when the integer X is found in the list ptr is not set to NULL and while enters an infinite cycle. Can someone help me?
Are you sure that here: ptr == NULL; should not be an assignment and not a comparison for equality?
– anonimo
Well observed kk, vlw
– GiovanniFilho05