Hey guys, just starting to learn C, and have a question.
I'm going through this tutorial series: https://www.youtube.com/watch?v=PVTD...6nhGJ9Vlcjyymq
And the first 'challenge' given by the presenter is giving me problems. Here's the code:
The user is supposed to input a password that contains at least one upper case letter, one number, and one symbol. If it contains all three of those things it returns "Password accepted!", if not it returns "Password cannot be used!". The problem is with the symbol part, as I have absolutely no idea how to determine which characters in the array have been left unused. As a result it always returns false positives.Code:#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <math.h> int main(){ char userPassword[30]; printf("Enter a password: "); scanf(" %s", userPassword); char blank[1]; int trueA, trueB, trueC; trueA = trueB = trueC = 0; int passLoop = 0; while (passLoop != 31) { if ((isalpha(userPassword[passLoop]) == 1)&&(isupper(userPassword[passLoop]) == 1)){printf("ALPHA!"); trueA = 1;} if (isdigit(userPassword[passLoop]) == 1) {printf("DIGIT!"); trueB = 1;} if ((isascii(userPassword[passLoop]) == 1)&&(isgraph(userPassword[passLoop]))&&(ispunct(userPassword[passLoop]))) {printf("ASCII!"); trueC = 1;} passLoop++; } if ((trueA == 1)&&(trueB == 1)&&(trueC == 1)) {printf("Password accepted!");} else {printf("Password cannot be used!");} return 0; }
Can any of you experienced C coders explain to me what the correct way to deal with this is?