Reputation: 35
I think it should work, what I try to do is capture a value and print it on screen, but I get the following error.
C:\Users\luis\Documents\c++\estructura de datos\ejemplo_lista.cpp In function 'void mostrar()': 80 13 C:\Users\luis\Documents\c++\estructura de datos\ejemplo_lista.cpp [Error] 'list' was not declared in this scope 80 20 C:\Users\luis\Documents\c++\estructura de datos\ejemplo_lista.cpp [Error] 'value' was not declared in this scope
------start MAIN---------------------------------
int main(){
menu();
show();
getch();
}
------end MAIN------------------------------------
//Function Menu
void menu()
{
NODE = NULL;
int choice;
int value;
while(choice!= 2){
printf("********** MENU **********\n");
printf ("1. Login data \n");
printf ("2. exit \n");
printf("**************************\n");
scanf ("%i",&choice);
switch (choice){
case 1:
printf("Please enter a value \n");
scanf("%i",&value);
add (list, value);
break;
case 2:
break;
}
system("pause");
}
}
input function
void add (NODE &list,int value)
{
NODE aux_list;
aux_list =(data_structure*) malloc (sizeof (data_structure));
aux_list->data = value;
aux_list->next = list;
list = aux_list;
}
void show()
{
NODE other_list;
add(list, value);
other_list = list;
/ / Display the elements of the list
while(other_list != NULL)
{
printf("%i \n",other_list->data);
other_list = other_list->next;
}
}
--------------------- edit --------------------------
ready to solve it this way
void mostrar(NODO lista,int valor)
{
lista=NULL;
Upvotes: 1
Views: 12717
Reputation: 4433
You forgot to declare the type of variable lista, or perhaps to declare it as a parameter in the function mostrar().
NODO lista; /* This one */
void mostrar(NODO lista) /* Or this one */
The object lista must be accesible inside the function mostrar().
(Update: The question has been changed to have English identifiers, so I will add the translated version below):
NODE list; /* This one */
void show(NODE list) /* Or this one */
Upvotes: 1
Reputation: 4939
In mostrar()
you attempt to use a variable lista. But lists in not decleared in that scope. You need to pass it as a parameter, or declare this variable in the function to avoid this error.
Upvotes: 1
Reputation: 3801
As the error message tells you, in function void mostrar()
you use variables lista
and valor
that are not defined in the scope of this function.
Upvotes: 1