Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:15:13+00:00 2026-05-26T10:15:13+00:00

How can I go back to the main function from another sub function? in

  • 0

How can I go back to the main function from another sub function?
in C programming

in main() the user is asked whether he want games or calculator.
if he chooses games for example, he will be going to the function games
when he is in games function he can choose which game he wants or going back to
the main menu which shows games and calculator.

eg:

//prototypes 
function one
function sub_one

main() {

select the function :
games:1
calculator:2 
go to ?(function games)?: .... 
}

//////////////////////////// 
function games { 

select the game :     
snake:1
painter:2
want to go back? yes? main()  
}

//////////////////////////// 
function snake {
  a+b .. get my work done here and i wanna goo back to games()
  want to go back? yes? function games()  
}

I succeeded to go back to previous functions except from the one which is pointed to in main().

I tried to define a global var and use it in a while loop inside main() in order to change
it from any function to be able to go back from any part of my code.

It seems pretty easy but I have lost my patience because I spent all my day trying
to do this thing and that’s why I am seeking a little hint from you.

Thank you so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:15:14+00:00Added an answer on May 26, 2026 at 10:15 am

    How you return to the main function depends upon how you declared your other functions:

    • if you declare the function void function (...), then you can simply return at any point, or allow control to run off the end of the function — the compiler will automatically return to the calling function

    • if you declare the function to return a value int function(...) or char * function(...) then you must return foo; from your functions — and foo‘s type must match the return type of the function. You cannot simply allow control to run off the end of the function.

    Some examples:

    #include <stdlib.h>
    #include <stdio.h>
    
    #define SNAKE 1
    #define PAINTER 2
    
    void play_snake() {
        /* play the snake game */
        return;
    }
    
    void play_painter() {
        /* sistine chapel time */
        return;
    }
    
    int prompt_for_choice() {
        char choice[10];
        puts("Please make a choice");
        puts("");
        puts("1 play snake");
        puts("2 play painter");
        fgets(choice, sizeof(choice), stdin);
        return strtol(choice, NULL, 10);
    }
    
    int main(int argc, char* argv[]) {
        int choice;
    
        choice = prompt_for_choice();
    
        if (choice == SNAKE) {
            play_snake();
        } else if (choice == PAINTER) {
            play_painter();
        } else {
            printf("internal error, invalid choice %d\n", choice);
            exit(1);
        }
    
        exit(0);
    }
    

    Note that there is nothing special about main. It is just another function.

    I strongly recommend getting a good book about C. My favorite “first book” is The C Programming Language. Be sure to get the second edition, as the first edition describes an earlier version of the language. (The first edition might still be fun reading, but does not accurately represent the C language as it is used today.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

how can i pass values from my custom components back to the main.mxml? i
I'm trying to return XML from an event complete back to the main function,
Is there a way I can piggy back sessions to know if the user
How can I pass back some arguments from a window that is closed? For
How can I revert back to the default function that python uses if there
I am starting to use the jquery $.ajax() but I can't get back what
i posted some data using tinymce (in a symfony project).while retrieving back how can
Can I use two different back ends for an .net Entity Framework project? I
Can an Ajax-enabled WCF Service pass back a DataTable as a Sys.Data.DataTable? Like this
Can anyone please suggest a way to replace back-slash '\' with slash '/' in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.