C Strings

I need help creating 3 functions. In the program the user enters a password but it must meet specific details. When I try these methods they fail how can I edit them to work. Should I use a different C String function?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Check for special character
    int sc;
    char scset[] = "!$%";
    sc = strcspn (passwd, scset);
    if (sc == 0) {
        cout << "No numeric character found." <<  endl;
    }
return false;

// Check that the password does not begin with ? or !
    if (passwd[0]=='?' || passwd[0]=='!') {
        cout << "Password must not being with ! or ?." << endl;
    }
return false;

// Check that the first 3 characters are not equivalent
    if (passwd[0] == passwd[1] == passwd[2]) {
        cout << "First three characters must not be the same." << endl;
    }
return false;
You are placing your return statements in the wrong location. Place them at the end of the if statement.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Check for special character
    int sc;
    char scset[] = "!$%";
    sc = strcspn (passwd, scset);
    if (sc == 0) {
        cout << "No numeric character found." <<  endl;
        return false;
    }

// Check that the password does not begin with ? or !
    if (passwd[0]=='?' || passwd[0]=='!') {
        cout << "Password must not being with ! or ?." << endl;
        return false;
    }

// Check that the first 3 characters are not equivalent
    if (passwd[0] == passwd[1] == passwd[2]) {
        cout << "First three characters must not be the same." << endl;
        return false;
    }

Because code will return false all the time.
Topic archived. No new replies allowed.