password with mixed upper & lower case & special characters/ password lenght is mini 8

Write your question here.
hi, i'm a beginner from the root of the tree, and i cannot solve this project for days now, help is needed.
when i compile, the msg < [Linker error] undefined reference to `testUpper(char)'
shows up
thank you
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <cctype>
#include <cstring>

using namespace std;

void testLength(char);
void testUpper(char);
void testLower(char);
void testSpecial(char);
const int minlength = 8;
int main()
{
    char ptrPass;
    const int Size = 15;
    char password[Size];
    cout <<"Enter a password:";
    cin >> password;
    ptrPass = password[Size];
    testLength(ptrPass);
    testUpper(ptrPass);
    testLower(ptrPass);
   // testSpecial(ptrPass);
    system("pause");
    return 0;
}

void testLength(char password[])
{
    int length;
    length = (strlen(password));
    if(length <= minlength)
    {
        cout << "Your password is too short. Please choose a password that is at  least 8 characters long." << endl;
    }
}

void testUpper(char password[])
{
    int length;
    bool upper = false;
    length = (strlen(password));
    for(int i=0; i < length; i++)
    {
        if(isupper(password[i]))
            upper = true;
    }
    if(!upper)
    {
        cout << "Your password must mixed case" << endl;
    }
}
void testLower(char password[])
{
   int length;
    bool lower = false;
    length = (strlen(password));
    for(int i=0; i < length; i++)
    {
        if(islower(password[i]))
        
            lower = true;
    }
    if(!lower)
   {
        cout << "Your password must mixed case" << endl;
    }
}
Last edited on
Maybe instead of using a char password[] as the type of the argument for the toUpper function why don’t you try out char *? I’m not entirely sure that will work, but might as well
if you remove the unimportant parts you see this:

1
2
3
4
5
6
7
8
    char ptrPass;
    char password[Size];
    cout <<"Enter a password:";
    cin >> password;
    ptrPass = password[Size]; //this is a memory access error.  c++ is 0 to size-1
    testLength(ptrPass); //void testLength(char password[]) type mismatch char array vs char
    testUpper(ptrPass); //as above
    testLower(ptrPass); //and again 


what is it you want to DO? Do you want to ensure that a word has one uppercase letter, one lower, one special? If so, then iterate all the letters in it until you see if it has them.
If you wanted performance, you would loop over the letters once like this:

1
2
3
4
5
6
7
8
9
bool special = false; bool upc=false; bool lowc=false;
for(int x = 0; x < strlen(password) && !(special&&upc&&lowc); x++)
 {
//   check each letter and set appropriate Boolean for it
     special |= issspecial(password[x]);  //looks like you were asked to write these
     upc |= isupper(password[x]); 
     lowc |= islower(password[x]); 
}
return special&&upc&&lowc; //return true if it has all 3 else false.  


cin >> password; this is also at risk of memory problems if user types 20 letters etc. this is a risk when using c-strings. You should use string c++ type once you cover that in your studies. You may want to make it extra long like 100 chars for now just as a precaution.
Last edited on
Hi Jonnin, the password must have lower, upper , special digit ,all in 8 characters,
ok. Whether you do it all in one as I did or not you still need to fix that memory error and check the letters 1 by one etc.

Someone didn't like my code, I see.
Topic archived. No new replies allowed.