Skip to content

Commit edf2c30

Browse files
committed
feature: prevent empty space name
1 parent 357beda commit edf2c30

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/play/utilities.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "../player/main.h"
1010

1111
unsigned char requestPlayerNames(SList *players) {
12-
char *lineBreak;
13-
1412
Player player;
1513
char playerName[PLAYER_NAME_LENGTH];
1614

@@ -19,10 +17,9 @@ unsigned char requestPlayerNames(SList *players) {
1917
fgets(playerName, PLAYER_NAME_LENGTH, stdin);
2018
puts("");
2119

22-
lineBreak = strrchr(playerName, '\n');
23-
if (lineBreak != NULL) *lineBreak = '\0';
20+
trimString(playerName);
2421

25-
if (*playerName == '0') return 0;
22+
if (strlen(playerName) == 0 || *playerName == '0') return 0;
2623

2724
newPlayer(&player, playerName);
2825

@@ -34,10 +31,9 @@ unsigned char requestPlayerNames(SList *players) {
3431
fgets(playerName, PLAYER_NAME_LENGTH, stdin);
3532
puts("");
3633

37-
lineBreak = strrchr(playerName, '\n');
38-
if (lineBreak != NULL) *lineBreak = '\0';
34+
trimString(playerName);
3935

40-
if (*playerName == '0') break;
36+
if (strlen(playerName) == 0 || *playerName == '0') break;
4137

4238
newPlayer(&player, playerName);
4339

0 commit comments

Comments
 (0)