Chapter19ex1.c 903 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. main(void)
  5. {
  6. int i;
  7. int hasUpper, hasLower, hasDigit;
  8. char user[25], password[25];
  9. hasUpper = hasLower = hasDigit = 0;
  10. printf("What is your user name? ");
  11. scanf(" %s", user);
  12. printf("Please create a password: ");
  13. scanf(" %s", password);
  14. for (i = 0; i < strlen(password); i++)
  15. {
  16. if (isdigit(password[i]))
  17. {
  18. hasDigit = 1;
  19. continue;
  20. }
  21. if (isupper(password[i]))
  22. {
  23. hasUpper = 1;
  24. continue;
  25. }
  26. if (islower(password[i]))
  27. {
  28. hasLower = 1;
  29. }
  30. }
  31. if ((hasDigit) && (hasUpper) && (hasLower))
  32. {
  33. printf("\nExcellentwork, %s, \n", user);
  34. printf("Your password has upper, lowercase, letters, and a number.");
  35. } else
  36. {
  37. printf("\n\nYou should consider a new password, %s,\n", user);
  38. printf("One that has upper, lowercase and a number.");
  39. }
  40. return(0);
  41. }