warning: NULL used in arithmetic

is there any way to disable the warnings by something like -Wno? I know they say you shouldn't use null in arithmetic anyway, but I'm just using it as a quick fix, and it bugs me that i'm getting like 7 warnings for it and not any other errors or warnings.


Besides whats the worse that could happen?
Can we see the expression?
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
Menu:
    
    cout << " Game Menu:" << endl;
while(1){
                int choice;  
                char c[1000];
                c[0] = ' '; c[1] = NULL;
                cout << endl;
                cout << " Enter 1 for Option A " << endl;
                cout << " Enter 2 for Option B " << endl;
                cout << " Type 'Exit' to exit. " << endl;
                cout << " Type 'Menu' to quit Puzzle and Return to Main Menu.   " << endl;
                enter:printf("%s"," >");
                cin.clear();
                string templine;
                templine = getstring();
                assign(templine, c);
                if (stringigual("exit", c) ) exit(0); 
                if (stringigual("menu", c) ) return false; 
                if (c[1] == NULL)
                    {
                       choice = c[0] -48; cout << "choice = " << choice << endl; 
                       if ((choice < 1) || (choice > 7))
                            { goto enter; }
                     } else choice = -1; 
                switch (choice)
                     {
                           case 1: option1(); break;
                           case 2: option2(); break;
                           default: nada(); break;
                      }
            }//end of while loop


here is the rest you might need:
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

bool assign (const string & s, char c[])
{
    bool successfull = false;
    if (s[0] != NULL && s[0] != '\n')
        {
            successfull = true;
        }
    else return false;
    for (int i = 0; i < 1000; ++i)
        {
            if ( (s[i] == NULL) || (s[i] == '\n') )
                {
                    break;
                }
            c[i] = s[i];
        }
    return successfull;
}

bool stringigual (const string & s, const char c[])
{

    //maybe do something for caps/lowercase
    string temp = s;
    for (int i = 0; i < temp.length(); ++i)
        {//caps thing goes here
            temp[i] = toupper(s[i]);
        }
    if ( (c[0] == NULL) || ( s[0] == NULL) )
        return false;
    int i = 1;
    do {
        if ( islower(c[i]) )
            {if ( (char( c[i] + 224)) != temp[i] )
                return false;}
        else
        if (c[i] != temp[i])
            return false;
        ++i;
    }while ( (c[i] != NULL) && (c[i] != '\n') );
    if (s.length() > i)
        return false;
    else return true;
}

string getstring()
{
    cin.clear();
    string local = ""; string temp = "";
    getline(cin, local);
    return local;
}
Basically what it does is allows the user to prompt either a string of chars, or single digits. So both chars and ints are used. But I need to evaluate if the user entered a string of more than 1 character, if so then it is assumed that it is not a digit.
You don't really need NULL for this. NULL is typically used for pointers, but it really is just a macro for 0. Using NULL here, while not incorrect, just feels out of place.
Just use zero.

And, by the way,
1
2
3
4
5
6
7
if (a==0)
//equivalent:
if (!a)

if (a!=0)
//equivalent:
if (a)
Topic archived. No new replies allowed.