I have a problem with the following program, I introduce a first data through the function add and the data is saved without problem, to the second round and try to enter a second data along with another node the program jumps with a error and it closes "In windows it tells me that the program has stopped".
#include <stdio.h>
#include <stdlib.h>
typedef struct nodo{
int dato;
struct nodo *siguiente;
}Nodo;
typedef Nodo *list;
typedef Nodo *pnodo;
void agregar_lista1(list *inicio,list *ultimo);
void agregar_lista2(list *inicio2,list *ultimo2);
void mostrar_lista();
int main (){
int op;
list inicio = NULL ,inicio2 = NULL,ultimo = NULL,ultimo2 = NULL;
do{
printf ("MENU");
printf ("\nOp1 Ingresar nodo en la lisata 1");
printf ("\nOp2 Ingresar nodo en la lisata 2");
printf ("\nOp3 Mostar los datos almacenados en la lista");
printf ("\nOp4 Mostrar suma de las listas anteriores\n\n");
scanf ("%d",&op);
switch(op){
case 1:
agregar_lista1(&inicio,&ultimo);
break;
case 2:
agregar_lista1(&inicio2,&ultimo2);
break;
case 3:
printf ("\n\nLista 1\n\n");
mostrar_lista(inicio);
printf ("\n\nLista 2\n\n");
mostrar_lista(inicio2);
break;
case 4:
break;
}
}while (op!=4);
return 0;
}
void agregar_lista1(list *inicio,list *ultimo){
pnodo nue,act;
nue=malloc(sizeof(Nodo));
if (nue==NULL){
printf ("\nNo se pudo crear el nodo\n");
}
printf ("Ingrese un numero entero positivo: ");
scanf ("%d",&nue->dato);
if (*inicio == NULL){
*inicio = nue;
nue->siguiente = NULL;
act = nue;
}
else{
act->siguiente = nue;
nue->siguiente = NULL;
act=nue;
}
printf ("\n\n%i\n\n",nue->dato);
}
void mostrar_lista(inicio){
pnodo ptr;
ptr = inicio;
if (inicio != NULL){
while (ptr != NULL){
printf ("\nDato %d \n",ptr->dato);
ptr = ptr->siguiente;
}
}
else {
printf ("\n\nLa lista esta vacia\n\n");
}
}