I'm tending to create a program that as I go in with the values, it adds at the beginning of the list chained, so I saw it is storing the values right, but at the time of printing it not printa, as if the list it was empty, I looked for the error and I did not find but I think it is related to the pointer in the function of insert, can someone show me the error? I really need to learn that soon.
#include <stdio.h>
#include <stdlib.h>
struct cel
{
int valor;
struct cel * prox;
};
typedef struct cel celula;
int inserir(celula *ini);
void escreve(celula *ini);
void main()
{
int i,aux;
celula *inicio;
inicio = NULL;
i=0;
do
{
printf("\nLista[%d]:",i+1);
aux = inserir(&inicio);
printf("\n%d",aux);
i++;
} while (aux == 1);
escreve(&inicio);
}
int inserir(celula *ini)
{
int n;
celula * aux;
aux = (celula*) malloc(sizeof(celula));
scanf("%d",&n);
if(n == 0)
return 0;
aux->valor = n;
aux->prox = ini;
ini = aux;
return 1;
}
void escreve(celula *ini)
{
int i=1;
celula * aux;
aux=ini;
while(aux->prox != NULL)
{
printf("\nlista[%d]=%d",i,aux->valor);
i++;
aux = aux->prox;
}
}