~ols/wordcalc

66087dc5a19b4c4a80ce8a83b7b70fd2436697d6 — Oliver Leaver-Smith 2 years ago 3fba69f master
Condensed if blocks with boolean magic
1 files changed, 5 insertions(+), 4 deletions(-)

M wordcalc.c
M wordcalc.c => wordcalc.c +5 -4
@@ 15,13 15,13 @@ int isValidWord(char word[])

    for (int i = 0; i < length; i++)
    {
        if (isalpha(tolower(word[i])) == 0)
        if (!isalpha(tolower(word[i])))
        {
            return 1;
            return 0;
        }
    }

    return 0;
    return 1;

}



@@ 58,6 58,7 @@ void printMessage(char *message)
// Validate number of aguments
// Validate all characters in word are letters
// Print result to console
// Returns exit code as 0 (success) or 1 (failure)
int main(int argc, char **argv)
{
    if (argc != 2)


@@ 78,7 79,7 @@ int main(int argc, char **argv)
    // Convert 'argument' string to 'word' array
    strcpy(word,argument);

    if (isValidWord(word) != 0)
    if (!isValidWord(word))
    {
        printMessage("Word fails validation, you probably have symbols or numbers in there");
        return 1;