954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert ANSI characters to character

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

FTProtocol
Junior Poster
102 posts since May 2008
Reputation Points: -14
Solved Threads: 1
 
RenjithVR
Light Poster
41 posts since Mar 2008
Reputation Points: 12
Solved Threads: 7
 

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
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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);
invisal
Posting Pro
562 posts since Mar 2005
Reputation Points: 350
Solved Threads: 64
 

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

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
>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*.

invisal
Posting Pro
562 posts since Mar 2005
Reputation Points: 350
Solved Threads: 64
 

Yep, there was a discussion on that not so long ago on the last few posts. http://www.daniweb.com/forums/thread130222.html

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You