0
I was trying to make a chained list, but I can’t get her to insert it or print it. If anyone can bring a light to my program I thank you.
#include <stdio.h>
#include <stdlib.h>
typedef struct cel celula;
struct cel{
int dado;
celula *prox;
};
void inicializar(celula *p,celula *aux);
int inserir(celula *p,celula *aux,int count,int valor);
void imprimir(celula *p,celula *aux,int count);
main()
{
celula *p, *aux;
int count=0,chave,valor;
inicializar(&p,&aux);
printf("Digite o tipo de entrada:\n");
printf("1 - Inserir numero;\n");
printf("2 - Imprimir lista de numeros;\n");
printf("3 - Sair.");
while(chave!=3)
{Restart:
printf("\nInsira a chave: ");
scanf("%d",&chave);
switch(chave){
case 1:
printf("\nDigite o valor a ser inserido: ");
scanf("%d",&valor);
count=inserir(&p,&aux,count,valor);
break;
case 2:
imprimir(&p,&aux,count);
break;
case 3:
printf("\nPrograma encerrado!\n");
break;
default:
printf("\nChave incorreta!\n");
goto Restart;
}
}
}
void inicializar(celula *p,celula *aux)
{
p=NULL;
aux=NULL;
}
int inserir(celula *p,celula *aux,int count,int valor)
{
if(count == 0)
{p=(celula *)malloc(sizeof(celula));
aux=p;
p->dado=valor;
p->prox=NULL;
printf("%d/%d",p->dado,count);
getch();
count ++;
return count;
}
else
{aux->prox=(celula *)malloc(sizeof(celula));
aux=aux->prox;
aux->dado=valor;
printf("%d/%d",aux->dado,count);
getch();
aux->prox=NULL;
count ++;
return count;
}
}
void imprimir(celula *p,celula *aux,int count)
{
int i;
for(i=0;i<count;i++)
{printf("%d ",p->dado);
p->prox;
}
}