While Infinite Loop in C

Asked

Viewed 64 times

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?

  • 1

    Are you sure that here: ptr == NULL; should not be an assignment and not a comparison for equality?

  • Well observed kk, vlw

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.