0

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++?

6
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by William Hemsworth
0

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 == '\"')

0

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);
1

>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.

Votes + Comments
thanks
0

>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*.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.