void viewMenu(){
//code
viewSellMenu();
}
void viewSellMenu(){
//code
viewMenu();
}
How do i have to code those 2 function so they can have a mutual relation?
void viewMenu(){
//code
viewSellMenu();
}
void viewSellMenu(){
//code
viewMenu();
}
How do i have to code those 2 function so they can have a mutual relation?
To call a function, the compiler needs to know its declaration, i.e. what's it called, that it's a function, and what the parameters and return type are:
void viewSellMenu(void); // declaration of viewSelMenu
// *definition* of viewMenu also serves as declaration
void viewMenu(){
//code
viewSellMenu(); // can be called because compiler knows declaration
}
// *definition* of viewSelMenu
void viewSellMenu(){
//code
viewMenu();
}
To use an identifier, it must be "visible" to the compiler. In C, visibility is from top to bottom. So, you have to add a declaration to a function above the function that calls it:
void viewSellMenu();
// rest of code
Since you call the function viewSellMenu()
with no arguments, consider changing it's signature to:
void viewSellMenu(void);
and when you define it, write:
void viewSellMenu(void)
{
viewMenu();
}
Same goes for viewMenu()
.
Note: If a function definition exists above a function that calls it, then you don't have to add a declaration.