Slight change to reset prompt to allow mix-cased response

This commit is contained in:
Tiehuis 2015-02-23 16:07:13 +13:00
parent 2d9af767d1
commit 1e2b2b76ac

View File

@ -1,3 +1,4 @@
#include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -41,6 +42,11 @@ static const char* highscore_retrieve_file(void)
return buffer; return buffer;
} }
static inline void string_to_lower(char *str)
{
for (; *str; ++str) *str = tolower(*str);
}
void highscore_reset(void) void highscore_reset(void)
{ {
const char *hsfile = highscore_retrieve_file(); const char *hsfile = highscore_retrieve_file();
@ -51,21 +57,15 @@ void highscore_reset(void)
while (1) { while (1) {
fgets(resp, resp_length, stdin); fgets(resp, resp_length, stdin);
string_to_lower(resp);
const size_t sl = strlen(resp); const size_t sl = strlen(resp);
if (sl < resp_length) if (sl < resp_length)
resp[sl - 1] = '\0'; resp[sl - 1] = '\0';
if (!strncmp(resp, "Yes", resp_length) || if (!strncmp(resp, "yes", resp_length) || !strncmp(resp, "y", resp_length))
!strncmp(resp, "Y", resp_length) ||
!strncmp(resp, "yes", resp_length) ||
!strncmp(resp, "y", resp_length) )
goto reset_scores; goto reset_scores;
else if (!strncmp(resp, "no", resp_length) || !strncmp(resp, "n", resp_length))
else
if (!strncmp(resp, "No", resp_length) ||
!strncmp(resp, "N", resp_length) ||
!strncmp(resp, "no", resp_length) ||
!strncmp(resp, "n", resp_length) )
return; return;
printf("Please enter Yes or No\n"); printf("Please enter Yes or No\n");