Browse Source

add function for user input

remotes/origin/georg
KaffeeMaus 11 months ago
parent
commit
d9a87d61f7
  1. 20
      src/main/c/Georg/tictactoe.c
  2. 2
      src/main/c/Georg/tictactoe.h

20
src/main/c/Georg/tictactoe.c

@ -67,18 +67,26 @@ commandFunction getCommandById( struct command* commands, int id ){
return result;
}
char* getUserInput(){
static char userInput[MAX_INPUT_LENGTH];
printf( ":" );
fgets(userInput, sizeof(userInput), stdin);
size_t len = strlen(userInput);
if (len > 0 && userInput[len - 1] == '\n') {
userInput[len - 1] = '\0';
}
return userInput;
}
int startMenu( int code ){
if( code == 1 ){ // command test
return 1;
}
while( GAME.currentState == 0 ){
char userInput[50];
printf( ":" );
scanf( "%s", &userInput );
int nextState = 0;
nextState = handleCommand(userInput);
int nextState = handleCommand( getUserInput() );
if( nextState == -1 ){
printf("command not found!");

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

@ -1,6 +1,8 @@
#ifndef TICTACTOE_H
#define TICTACTOE_H
#define MAX_INPUT_LENGTH 20
struct ticTacToe{
int currentState;
};

Loading…
Cancel
Save