The program compiles but only shows the last item in the list to be entered and not the rest.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct nodo{
int valor;
struct nodo *sig;
};
int main(){
int opcion;
int valor;
struct nodo *lista;
lista = NULL;
struct nodo *aux;
aux = (struct nodo *)malloc(sizeof(struct nodo));
do{
printf("\n1- insertar elemento\n");
printf("2- mostrar lista \n");
printf("0- salir\n");
scanf("%d", &opcion);
switch(opcion){
case 1:
printf("ingrese un valor: ");
scanf("%d", &valor);
if(lista==NULL){
lista = (struct nodo *)malloc(sizeof(struct nodo));
lista->valor=valor;
lista->sig=NULL;
}
else{
lista->sig=aux;
aux->valor=valor;
aux->sig=NULL;
aux=lista;
}
break;
case 2: while(aux!=NULL){ //<- solo muestra el primer valor
printf("el valor del elemento es %d \n", aux->valor);
aux = aux->sig;
}
break;
case 0: printf("fin del programa \n");
break;
}
}while (opcion !=0);
getch();
return 0;
}