Solution for Exercise 13-7
ex1307
#include <stdio.h> #include <string.h> int main() { char password[]="taco"; char input[15]; int match; printf("Password: "); scanf("%s",input); match=strcmp(input,password); if(match==0) puts("Password accepted"); else puts("Invalid password. Alert the authorities."); return(0); }
Notes
* Perhaps the most important thing to remember when comparing strings in C is that the strcmp() series of functions do not return TRUE/FALSE values. They return zero when the strings compare, as shown at Line 14.
Copyright © 1997-2024 by QPBC.
All rights reserved