Skip to content

Commit 6f90172

Browse files
authored
Merge branch 'Master' into feature/case-insensitive
2 parents 4967e06 + 4b76dac commit 6f90172

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ int main(const int argsLength, char* args[]) {
2525
return 1;
2626
};
2727

28-
// reprConfiguration(&config);
29-
// printf("\n");
30-
3128
strcpy(team.name, config.teamName);
3229

3330
printf("> %s team - A Tic-Tac-Toe game developed with C...", DEVELOPMENT_TEAM);
3431

3532
printf("\n\n> Available options:\n\n%s%s%s", " 1 - Play Tic-Tac-Toe.\n", " 2 - Show ranking.\n",
3633
" 0 - Exit.\n");
3734

38-
printf("\n> Select a option: ");
35+
printf("\n> Select an option: ");
36+
fflush(stdin);
3937
scanf("%d", &userInput);
4038

4139
while (userInput != 0) {
@@ -48,13 +46,14 @@ int main(const int argsLength, char* args[]) {
4846
printf("\n> [Showing ranking...]");
4947
break;
5048
default:
51-
printf("\n> [Invalid operation! Try again...]");
49+
printf("\n> Invalid option! Try again...");
5250
};
5351

5452
printf("\n\n> Available options:\n\n%s%s%s", " 1 - Play Tic-Tac-Toe.\n",
5553
" 2 - Show ranking.\n", " 0 - Exit.\n");
5654

57-
printf("\n> Select a option: ");
55+
printf("\n> Select an option: ");
56+
fflush(stdin);
5857
scanf("%d", &userInput);
5958
};
6059

src/play/main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ unsigned char playTicTacToe(const Configuration* config, char* localFilePath) {
1818
newList(&players);
1919
newList(&playersAfterMatch);
2020

21-
requestPlayerNames(&players);
21+
if (!requestPlayerNames(&players)) {
22+
printf("> Error! An error occurred on get player names.");
23+
return 0;
24+
};
2225

2326
randomSort(&players);
2427

src/play/utilities.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ unsigned char requestPlayerNames(List* players) {
1414
player.points = 0;
1515
player.assignedForm = ' ';
1616

17-
do {
17+
printf("> Enter a player name (0 to exit): ");
18+
fflush(stdin);
19+
fgets(player.name, PLAYER_NAME_LENGTH, stdin);
20+
puts("");
21+
22+
lineBreak = strrchr(player.name, '\n');
23+
if (lineBreak != NULL) *lineBreak = '\0';
24+
25+
if (*(player.name) == '0' || !pushElement(players, &player, sizeof(player))) return 0;
26+
27+
while (*(player.name) != '0') {
1828
printf("> Enter a player name (0 to exit): ");
1929
fflush(stdin);
2030
fgets(player.name, PLAYER_NAME_LENGTH, stdin);
@@ -23,10 +33,9 @@ unsigned char requestPlayerNames(List* players) {
2333
lineBreak = strrchr(player.name, '\n');
2434
if (lineBreak != NULL) *lineBreak = '\0';
2535

26-
if (*(player.name) == '0') continue;
36+
if (*(player.name) == '0') break;
2737
if (!pushElement(players, &player, sizeof(player))) return 0;
28-
29-
} while (*(player.name) != '0');
38+
};
3039

3140
return 1;
3241
}

0 commit comments

Comments
 (0)