If I won't use adminact() to go back, what can I use?
I didn't quite understand what you were pointing out. XDQuote:
Originally Posted by Mr.777
Printable View
OK, let's say we have a menu() function, that shows the options we can choose. We choose addBook(), and add a book. Now, how do we get back to the menu again?
We simply do nothing! :D
Sample menu code:Without doing anything, after we call "addBook()", the program will return and execute the next code, which is "break". Then the menu will be printed up again.Code:void menu() {
int choice = 9;
while(choice != '0') {
printf("\n\n\n Welcome to the Library Menu\n\n");
printf("
1. Add a Book\n\
2. Delete a Book\n\
3. Edit a Book Record\n\
4. Search for a Book\n\
5. View all Books\n\n");
printf("Your Choice (0 to Quit) >> ");
scanf("%c", &choice);
(void) getchar();
choice = tolower(choice); //include ctype.h for tolower()
switch(choice) {
case 1: addBook(); break;
case 2: etc.
//etc.
} //end of switch
} //end of while
} //end of menu()
No recalling the menu() function is necessary. (And if you do it, it will break your program before long).
Now say we had a main menu() and an adminMenu(), and we're at the main menu(). So we choose adminMenu() to do some admin work, then we would loop back (first), to the adminMenu() function, just by returning. If we return again, we're now back at the main menu() function.
That's how the call stack works - like a plate stack in your kitchen. You put plates on the stack, and then remove them, always by taking off the top plate, not just ANY plate. Every time you add a plate to the stack of plates, it's a PUSH, and every time you remove a plate, it's a POP. Every time you call a function, it's a PUSH of the return address, onto the stack. Every time you return from a function, it's a POP off of the stack.
And now it's time to have some lunch! :D
Ahh... Right. XD