. Advertisement .
..3..
. Advertisement .
..4..
How to set hasdigit to true if the 3-character passcode contains a digit. Below is my code
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
int main(void) {
bool hasDigit;
char passCode[50];
hasDigit = false;
strcpy(passCode, "abc");
/* Your solution goes here */
if (hasDigit) {
printf("Has a digit.\n");
}
else {
printf("Has no digit.\n");
}
return 0;
}
Give me a few effective suggestions to set hasdigit to true if the 3-character passcode contains a digit.
You should add the following loop
Your code after rewritten is
I have simple answer and it works for me
Suggestion command could be solved to your problem
Be aware it is important to note that isdigit (and every function) does not always return 1 so comparing it with true is not correct. Simply check to see whether it returns zero or non-zero. That’s the value that isdigit is stated to return.
You’ll apply a similar loop for the second one and then do: