0
I’m tending to create a program that as I enter with the values, it adds at the beginning of the chained list, so I saw it holding the values just right, but when printing it does not print, as if the list is empty, I looked for the error and could not find but I think it is related to the pointer in the insert function, can anyone show me the error? I really need to learn this 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;
}
}
Try to put the idented code correctly. This will greatly facilitate the resolution of your problem.
– Phelipe
then I don’t know how to use stackoverflow, if you can explain to me how I put the code straight I thank you
– Guilherme Garcia
I tbm am not very experienced, but the way I do is to go in editing and identar on the same hand. Sometimes it’s worth it to take your code and put it in a text edit, come up with spaces (not tabs) and paste here.
– Phelipe
is that I had seen that if I used CTRL+K he would do this, but only now that I saw that I have to select the text and then press the shortcut, now it’s set straight
– Guilherme Garcia
detail plus error... occurs when you do what? What shows in error message?
– Anderson Henrique
edited there, but I think the pointer ta pointing to the wrong place, but as I am not very experienced I can not identify
– Guilherme Garcia