cctype doesn't have special characters function

It's a simple question

I am trying to find a way to use special characters in a function so I can use that reference later when I want to check if the character from the random word or a password to verify if its a special character...

P.S. it should be similar to isalpha, islower, isupper, isdigits, but how was the function look like??

here's what i have so far...
when i test it into my program it just stop after one character, unlike the other function I can go on detect each character... there must be something wrong with my loop in my " isSpecial(ch) "

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
bool isSpecial(char)                                 //function for finding symbols
{
    char symbols[] = {'#', '%', '$','*'};
    char ch;
    
    cin>> ch;
    
    int sub;
    
    for( sub = 0; sub< 4; sub++)
    {
        if(ch == symbols[sub] )
        {
            break;
        }
    }
    
    if( sub<4 )
    {
        return ch;
    }
    else
    {
        return 0;
    }
    
    return ch;
}
Last edited on
Have you seen this?
http://en.cppreference.com/w/cpp/string/byte/ispunct

You have quite a few issues with your function.
Here is one way to do implement what your trying to do.

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
#include <iostream>

using namespace std;

bool isSpecial(char ch)                                 
{
    bool rval = false;
    int size = 4;
    char symbols[size] = {'#', '%', '$', '*'};
    for (int i = 0; i < size; ++i) {
        if (symbols[i] == ch)
            rval = true;
    }
    return rval;
}

using namespace ::std;

int main() {
    cout << std::boolalpha << isSpecial ('3') << endl;
    cout << std::boolalpha << isSpecial ('#') << endl;

}


Bdanielz

I didn't see the ispunct, because I was looking at islower, isupper, is alpha, isdigits the whole time....
Last edited on
Thanks Bdanielz!!

it works!!!

you the man!
Topic archived. No new replies allowed.