Browse Source

added a function that create the command list

remotes/origin/georg
KaffeeMaus 11 months ago
parent
commit
0516a82cb0
  1. 22
      src/main/c/Georg/tictactoe.c
  2. 5
      src/main/c/Georg/tictactoe.h

22
src/main/c/Georg/tictactoe.c

@ -32,12 +32,30 @@ int handleCommand( char* input ){
} }
} }
struct command* createCommands(){
struct command commands[] = {
{"\"start menu\" - startet das menu", startMenu}
};
size_t numCommands = sizeof(commands) / sizeof(commands[0]);
// Dynamischen Speicher für das Array von commands reservieren
struct command* ptrCommands = (struct command*)malloc(numCommands * sizeof(struct command));
// Über das lokale Array iterieren und Daten kopieren
for (size_t i = 0; i < numCommands; i++) {
ptrCommands[i] = commands[i];
}
return ptrCommands;
}
int startMenu(){ int startMenu(){
return 0;
return 1;
} }
int startGame(){ int startGame(){
return 0;
return 1;
} }

5
src/main/c/Georg/tictactoe.h

@ -8,6 +8,11 @@ struct ticTacToe{
// Typdefinition für einen Funktionszeiger // Typdefinition für einen Funktionszeiger
typedef int (*commandFunction)(); typedef int (*commandFunction)();
struct command{
char* description;
commandFunction fun;
};
char* getWelcomeMessage(); char* getWelcomeMessage();
char* getRulesMessage(); char* getRulesMessage();
struct ticTacToe createTicTacToe(); struct ticTacToe createTicTacToe();

Loading…
Cancel
Save