Help with library system

This is a discussion on Help with library system within the C Programming forums, part of the General Programming Boards category; Originally Posted by Salem Well apart from the train wreck of using gets(), the next problem I see is your ...

  1. #16
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    Quote Originally Posted by Salem View Post
    Well apart from the train wreck of using gets(), the next problem I see is your recursive calls to adminact(); every time you finish something.

    viewbook() for example should just return; and it is right back in the middle of adminact() where it was called from.

    If you want a normal user to call viewbook(), you would want to return to the normal user function as well.
    If I won't use adminact() to go back, what can I use?

    Quote Originally Posted by Mr.777
    Practically, you can't remove from the static arrays, and also you are assigning the title as " ".
    So, in viewbook function, don't show the books which have title as " ".
    Simple :-)
    I didn't quite understand what you were pointing out. XD

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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!
    Sample menu code:
    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()
    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.

    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!

  3. #18
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    Quote Originally Posted by Adak View Post
    choice = tolower(choice)
    [/code]
    What does the tolower() function do?

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by hexarthrius View Post
    What does the tolower() function do?
    Seriously? Learn to internets.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by hexarthrius View Post
    What does the tolower() function do?
    Look it up in your library documentation...

  6. #21
    Registered User
    Join Date
    Mar 2011
    Posts
    10
    Ahh... Right. XD

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 09:06 AM
  2. Replies: 1
    Last Post: 08-16-2009, 05:49 AM
  3. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  4. Library Wrapper
    By cusavior in forum C Programming
    Replies: 3
    Last Post: 03-25-2008, 10:27 AM
  5. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 05:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21