Solution for Exercise 13-8

ex1308

#include <stdio.h>
#include <string.h>

int main()
{
    char password[]="taco";
    char input[15];

    printf("Password: ");
    scanf("%s",input);

    if(strcmp(input,password)==0)
        puts("Password accepted");
    else
        puts("Invalid password. Alert the authorities.");

    return(0);
}

Notes

* Minus the variable match, you must use the strcmp() function as the if statement's condition, shown in Line 12.

* Give yourself a slew of For Dummies bonus points if your if statement looks like this:

The ! reads as "not," which reverses the outcome of the strcmp() function. So if it returns zero (normally a FALSE according to if), the not result would make it TRUE, which satisfies the if statement's condition as a match.