1.
Set hasDigit to true if the 3-character passCode contains a digit.
#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;
}
What I tried (in place of /* Your solution goes here */ is:
if (isdigit(passCode) == true) {
hasDigit = true;
}
else {
hasDigit = false;
}
when testing
abc
it works, but when testing
a 5
it doesnt work.
2.
Replace any space ' ' with '_' in 2-character string passCode. Sample output for the given program:
1_
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void) {
char passCode[3];
strcpy(passCode, "1 ");
/* Your solution goes here */
printf("%s\n", passCode);
return 0;
}
What I put in place of /* Your solution goes here */ is:
if (isspace(passCode) == true) {
passCode = '_';
}
And it fails to compile.
Thanks for all help.