From a8cb10f119b8f3244d003c6733cdd16c2079ab55 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Mon, 24 Jan 2022 10:51:00 -0500 Subject: swipeGuess: insensitive comparison --- swipeGuess.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'swipeGuess.c') diff --git a/swipeGuess.c b/swipeGuess.c index dad4548..41fb29c 100644 --- a/swipeGuess.c +++ b/swipeGuess.c @@ -1,6 +1,7 @@ #include #include #include +#include #define BUFSIZE 1024 char wordBuff[BUFSIZE]; @@ -20,15 +21,21 @@ char *fgetst(char *restrict s, int size, FILE *restrict stream) { return r; } +bool charcmp(char a, char b) { + return tolower(a) == tolower(b); +} + bool swipeCompare(char *swipe, char *word) { - if (swipe[0] != word[0]) return false; + if (! charcmp(swipe[0], word[0])) { + return false; + } char *swipeP = swipe; char *wordP = word; wordP++; bool lastMatch = false; for(swipeP++; swipeP[0]; swipeP++) { lastMatch = false; - while (swipeP[0] == wordP[0]) { + while (charcmp(swipeP[0], wordP[0])) { wordP++; lastMatch = true; } -- cgit 1.4.1