0
Hello, please consider the structure and functions given below and the types defined. In the main function, when you enter the odd even function of the error of Segmentation fault. I don’t understand why this is. Could someone help me, please?
    #include <stdio.h>
    #include <stdlib.h>
    typedef struct cel {
        int info;
        struct cel * prox;
    } celula;
    typedef celula * apontador;
    /*dado um apontador (lista) imprime o camp info recursivamente*/
    void imprimeRec(apontador inicio) {
        if (inicio != NULL) {
            printf("%d\n", inicio->info);
            imprimeRec(inicio->prox);
        }
    }
   /*dada uma lisata ligada, insere um no no final*/
apontador insereNoFimRec(apontador inicio, int x) {
    apontador novo;
    if (inicio == NULL) {
        novo = malloc(sizeof(celula));
        novo->info = x;
        novo->prox = NULL;
        return novo;
    }
    inicio->prox = insereNoFimRec(inicio->prox, x);
    return inicio;
}
    /*recebe um int n e retorna um apaontador para uma lista ligada*/
    apontador criaLista(int n) {
        int i = 0;
        int info;
        apontador lista = NULL;
        while (i < n) {
            printf("L[%d] = ", i);
            if (!scanf("%d", &info))
                return NULL;
            lista = insereNoFimRec(lista, info);
            i++;
        }
        return lista;
    }
    void parImpar(apontador *par, apontador *impar, apontador inicio) {
        apontador t1, t2;
        t1 = t2 = NULL;
        if ((inicio->info % 2) == 0)
            *par = t1 = inicio;
        else
            *impar = t2 = inicio;
        inicio = inicio->prox;
        while (inicio != NULL) {
            if ((inicio->info % 2) == 0) {
                t1->prox = inicio;
                t1 = t1->prox;
            }
            else {
                t2->prox = inicio;
                t2 = t2->prox;
            }
            inicio = inicio->prox;
        }
        t1 = t2 = NULL;
    }
    int main() {
        int tamanho;
        apontador lista, *par, *impar;
        par = impar = NULL;
        printf("Tamanho da lista: ");
        if (!scanf("%d", &tamanho))
            return 0;
        lista = criaLista(tamanho);
        imprimeRec(lista);
        printf("Agora, vamos separar a ultima lista em numeros pares e impares\n");
        parImpar(par, impar, lista);
        printf("Par:\n");
        imprimeRec(*par);
        printf("Impar:\n");
        imprimeRec(*impar);
        return 0;
    }
						
Thanks for the answer, @josuegomes. It turns out that the exercise asks to do this by manipulating the pointers within the function. I guess I forgot to mention that detail.
– Lucas Lopes
Inside the parimpar() function you will continue handling as pointers.
– josuegomes