K so atm, I'm having problems understanding ENDIF and IFDEF preprocessor stuff.. I want to Use a specific method if a file is included.. If not, use a different method..

Since toupper is defined in CCType I tried to check if that file was included.. if it was, use toupper else use the hex values.. I'm not sure which method is optimum or faster or whatever so I decided to do it this way. By include.

Any help is appreciated. +1 as I cannot find it on the net anywhere.. Just a bunch of tuts on #Defines instead of includes.

Also how do I check "IF NOT #Included or #Define"??

string ToUpper(string Str)
{
    #ifdef CCTYPE
    for (unsigned short I = 0; I < Str.length(); I++)
    {
        Str[I] = toupper(Str[I]);
    }
    #else
        for (unsigned short I = 0; I < Str.size(); I++)
        if(Str[I] >= 0x61 && Str[I] <= 0x7A)
            Str[I] = Str[I] - 0x20;
    #endif
    return Str;
}

Recommended Answers

All 2 Replies

Ever think about just including the cctype header in your project? If you dont want to do that then what you have looks good as long as CCTYPE is defined in the cctype header file. If you want to check if something is not defined then you would use #IFNDEF something

#ifndef is what you want to check if something has not been defined. Checking for the inclusion of a particular header will be depend on your compiler. you'll have to put some effort in to make it portable :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.