Dave C
Dave C

Reputation: 37

Where / How is null defined?

Null is not declared?

My code:

// Include necessary libraries
#include <cstdlib> // Exits
#include <iostream> // I/O
#include <cstring> // String functions
using namespace std;

int main(int argc, char *argv[])
{
    //Declare local Constants and Variables
    const char SOKINP[19] = "23456789TtJjQqKkAa"; // Valid Input Characters
    char acCards [5]; // Array to hold up to five cards (user input)
    bool bErr;        // Loop on Error (Calculated)
    int  i,           // Loop variable (Calculated)
    iNbrCrd,          // Number of Cards 2-5 (user input)
    iNAces,           // Number of Aces (Calculated)
    iTS;              // Total Score (Calculated)

    ...

    for (i=0;i<iNbrCrd;i++){
       do {
           cout << "Enter Card #" << i << " (2-9,t,j,q,k or a)  >";
           cin  >> acCards[i];
           cout << endl;
           bErr = (strchr(SOKINP, acCards[i]) == null) ? true : false; // *ERROR*
       } while (bErr);
    }
    return EXIT_SUCCESS;
}

[Error] 'null' was not declared in this scope

How do I declare 'null'? I tried including several other libraries. I'm using Dev C++ v5.4.2

Thanks, ~d

Upvotes: 0

Views: 3085

Answers (2)

Saksham
Saksham

Reputation: 9390

Use NULL instead of Null.

If you are using it to initialize a pointer and you are using C++11, use nullptr.

Although NULL works for assigning the pointers(even though NULL is not a pointer type but is integer), you may face problems in the below case:

void func(int n);
void func(char *s);

func( NULL ); // guess which function gets called?

Refer to THIS for more details

Upvotes: 3

The Light Spark
The Light Spark

Reputation: 504

Its not null. It's NULL in all caps. If writing NULL does not work, you can define it yourself by using

#define NULL 0

Upvotes: 6

Related Questions