欢迎。我有两个问题。首先 - function size bool (const char * pass) 检查字符串中的字符数是否至少为 8,但有问题。它总是显示至少有 8 个字符,即使字符串只包含 3 个字符。
我的工作是创建几个小函数来检查输入的字符串的正确性。你能帮你解决这个问题吗?如果 bool check(...) 中的所有小函数都返回 true,我需要在控制台中写入“STRING IS OKAY”。
我将不胜感激任何建议。
#include <iostream>
#include <cctype>
using namespace std;
//Check the amount of chars
bool size (const char* pass){
if(sizeof(pass) > 7)
return true;
}
//Checks if the ASCII are located between 32 to 126
bool isPrint (const char* pass){
for(int x=0; x <= sizeof(pass); x++){
if(isprint(pass[x]))
return true;
}
}
//Check the amount of numbers
bool isNum (const char* pass){
for(int x=0; x <= sizeof(pass); x++){
if(isdigit(pass[x]))
return true;
}
}
//Check the amount of Upper letters
bool isUpperLetter (const char* pass){
for(int x=0; x <= sizeof(pass); x++){
if(isupper(pass[x]))
return true;
}
}
//Check the amount of lower letters
bool isLowerLetter (const char* pass){
for(int x=0; x <= sizeof(pass); x++){
if(islower(pass[x]))
return true;
}
}
//Check the amount of Punctuation Marks
bool isPunctMark (const char* pass){
for(int x=0; x <= sizeof(pass); x++){
if(ispunct(pass[x])){
return true;
}
}
}
//All small moduls together
bool check (const char* pass){
size(pass);
isPrint(pass);
isNum(pass);
isUpperLetter(pass);
isLowerLetter(pass);
isPunctMark(pass);
}
int main() {
char x;
cout << "Enter the string of characters" << endl;
cin >> x;
const char *password = &x;
check(password);
}