Well in VB6 they use Chr()

example:

Do
            sChar = Chr(GetRandomNumber())
        Loop While sChar = Chr(34)

Just wondering if there is a similar function in c++?

Recommended Answers

All 6 Replies

Well in VB6 they use Chr()

example:

Do
            sChar = Chr(GetRandomNumber())
        Loop While sChar = Chr(34)

Just wondering if there is a similar function in c++?

Its not necessary to do that in C++ or C. A char can be freely used as either an integer or a character. Both the following are correct (equivalent). while( sChar == 34) or while( sChar == '\"')

Ancient Dragon said it all. char in C/C++ actually is a 8-bits integer ranging from 0 to 255. So you can write something like this:

for( sChar = rand()%256; sChar == 34; sChar = rand()%256);

>char in C/C++ actually is a 8-bits integer ranging from 0 to 255.
While that may be true on your PC, C and C++ don't require char to be an 8-bit type. Further, vanilla char is allowed to be either signed or unsigned (the choice is made by your compiler), in which case even an 8-bit char may not have the range you specified.

commented: thanks +4

>char in C/C++ actually is a 8-bits integer ranging from 0 to 255.
While that may be true on your PC, C and C++ don't require char to be an 8-bit type. Further, vanilla char is allowed to be either signed or unsigned (the choice is made by your compiler), in which case even an 8-bit char may not have the range you specified.

I have been defeated.... *waving white flag*.

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.