确定输入是否包含c中的算术运算符

确定输入是否包含c中的算术运算符,c,C,我想循环遍历数组arithchar中的字符,以确定输入的字符是否与之匹配 我的代码如下所示: int checkForAO(char password_entered[]); int main(){ if(checkForAO(password_entered)){ //contains a password with ao } else{ //doesnt contain special ao. } int chec

我想循环遍历数组arithchar中的字符,以确定输入的字符是否与之匹配

我的代码如下所示:

 int checkForAO(char password_entered[]);
 int main(){
    if(checkForAO(password_entered)){
        //contains a password with ao
    }
    else{
        //doesnt contain special ao.
    }

    int checkForAO(char password_entered[]){
        int i;
        char arithchar[4] = {'+','-','*','/'};
        for (i=0; i<strlen(password_entered); i++) {
            if ( <<<< password_entered[i] contains any character in arithchar array  >>>>>>> ) ) {
                printf("\nYour password contain(s) ao.\n");
                return true;
            }
        }
        printf("\nYour password didn't contain any ao.\n");
        return false;
    }
int checkForAO(输入字符密码[]);
int main(){
if(checkForAO(输入密码)){
//包含带有ao的密码
}
否则{
//不包含特殊ao。
}
int checkForAO(输入字符密码[]){
int i;
char arithchar[4]={'+','-','*','/'};
对于(i=0;i>>>)){
printf(“\n您的密码包含ao。\n”);
返回true;
}
}
printf(“\n您的密码不包含任何ao。\n”);
返回false;
}
我需要帮助,特别是在确定我的最后一个
if{}
语句时,我尝试了伪编码,但似乎无法解决这个问题


谢谢。

如果出现以下情况,我建议您添加以下行:

if ( password_entered[i] == '+' || password_entered[i] == '-' || password_entered[i] == '*' || password_entered[i] == '/') )
并删除以下行:

// char arithchar[4] = {'+','-','*','/'};
您的函数将变为:

 int checkForAO(char password_entered[]){
    int i;

    // char arithchar[4] = {'+','-','*','/'};
    for (i=0; i<strlen(password_entered); i++) {
        if ( password_entered[i] == '+' || password_entered[i] == '-' || password_entered[i] == '*' || password_entered[i] == '/') )
        {
            printf("\nYour password contain(s) ao.\n");
            return true;
        }
    }
    printf("\nYour password didn't contain any ao.\n");
    return false;
int checkForAO(输入字符密码[]){
int i;
//char arithchar[4]={'+','-','*','/'};

对于(i=0;i我建议您在以下情况下添加以下行:

if ( password_entered[i] == '+' || password_entered[i] == '-' || password_entered[i] == '*' || password_entered[i] == '/') )
并删除以下行:

// char arithchar[4] = {'+','-','*','/'};
您的函数将变为:

 int checkForAO(char password_entered[]){
    int i;

    // char arithchar[4] = {'+','-','*','/'};
    for (i=0; i<strlen(password_entered); i++) {
        if ( password_entered[i] == '+' || password_entered[i] == '-' || password_entered[i] == '*' || password_entered[i] == '/') )
        {
            printf("\nYour password contain(s) ao.\n");
            return true;
        }
    }
    printf("\nYour password didn't contain any ao.\n");
    return false;
int checkForAO(输入字符密码[]){
int i;
//char arithchar[4]={'+','-','*','/'};
for(i=0;i
for(i=0;i
for(i=0;i用于

例如

例如


使用
strchr()
的紧凑解决方案:

int checkForAO(输入字符密码[])
{

对于(i=0;i紧凑型解决方案,使用
strhr()

int checkForAO(输入字符密码[])
{

对于(i=0;i使用
for
语句代替该
if{}
语句尝试使用
for
语句代替该
if{}
语句