#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"); if ((isdigit(passCode[0])||(isdigit(passCode[1]))||(isdigit(passCode[2])))){ hasDigit = true; } if (hasDigit) { printf("Has a digit.\n"); } else { printf("Has no digit.\n"); } return 0; }
White space replace.
#include <stdio.h> #include <string.h> #include <ctype.h> int main(void) { char passCode[3]; strcpy(passCode, "1 "); if(passCode[1]== ' '){ passCode[1]='_'; }; if(passCode[0]== ' '){ passCode[0]='_'; }; printf("%s\n", passCode); return 0; }