Calling a function

This is a discussion on Calling a function within the C Programming forums, part of the General Programming Boards category; I'm writing a program that has a menu, where the user can make a choice. From main(), I want to ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    9

    Calling a function

    I'm writing a program that has a menu, where the user can make a choice. From main(), I want to call a function based on a choice. If the choice is a, I want it to go to a certain function. If its b, I want it to go to another function, and so on and so forth. Any suggestions/code would be helpful and appreciated.

  2. #2
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744
    I would do it with a switch statement
    Code:
    switch(choice)
    {
    case 'a':FunctionA();
                 break;
    case 'b':FunctionB();
                 break;
    case 'c':FunctionC();
                 bteak;
    default:printf("Wrong choise");
                break;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM

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