Main() function; inside an external function in an external file

Asked

Viewed 20 times

0

I would like to know if there is a possibility to include/call/return the function int main(){ within a case(x){ in an external file, to form a loop. I am developing an old game, and I am creating several files and calling them to the source code main. c to keep organized. I will try to explain with the codes below:

Here I would be during the game, but if player X won, he would have the option to return to the navigation menu.

//main.c
#include "functions/playerX.c"

int main(){
unsigned char game[3][3] = {'~','~','~','~','~','~','~','~','~'};

tralha(linha,coluna,game);

printf("O X seleciona a casa");
scanf("%hd", casa);

playerX(casa,game,option);

}

In case Player X typed 1 he would return to the beginning of the function int main(){ making a vicious loop, so there was no excessive repetition of code.

//playerX.c
void playerX(short unsigned int x){

switch(x){
case 1:
main();
break;
}
}

If there’s no possibility, there’s some resource I might be using to do something similar?

  • the command is called switch just. To do what you want put the one switch in main, treating the result returned by menu of course the user option. That’s how it’s done in general. Think you need an example?

  • I did not want to put the switch inside the main, because it is very extensive and would end up polluting the code.

  • change of place does not mean to clean up. But if you think so create a function like process() and inside use a loop that calls menu() to receive the option and the switch() to treat. And in main() calling processo()...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.