I have this code where I add values to the nodes of my linked list but when I view that list it shows me 0. I call the function addNodos () and enter the values that I want but I do not see the data correctly.
Code:
int main()
{
printf("Ingrese valores numericos hasta meter un 0\n\n");
agregarNodos();
visualizarLista();
return 0;
}
void agregarNodos()
{
Nodo *nuevo = (Nodo*)malloc(sizeof(nodo));
do{
printf("Numero: ");
scanf("%d",&nuevo->dato);
}while(nuevo->dato !=0);
if(principio==NULL)
{
principio=nuevo;
principio->siguiente=NULL;
final=nuevo;
}
else
{
final->siguiente=nuevo;
nuevo->siguiente=NULL;
final=nuevo;
}
}
void visualizarLista()
{
Nodo *actual = (Nodo*)malloc(sizeof(Nodo));
actual=principio;
if(principio!=NULL)
{
while(actual!=NULL)
{
printf("Dato: %d\n",actual->dato);
actual=actual->siguiente;
}
}
else
{
printf("\n La lista esta vacia");
}
}