943,740 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2526
  • C++ RSS
Jul 8th, 2008
0

Convert ANSI characters to character

Expand Post »
Well in VB6 they use Chr()

example:

C++ Syntax (Toggle Plain Text)
  1. Do
  2. sChar = Chr(GetRandomNumber())
  3. Loop While sChar = Chr(34)

Just wondering if there is a similar function in c++?
Similar Threads
Reputation Points: -14
Solved Threads: 1
Junior Poster in Training
FTProtocol is offline Offline
99 posts
since May 2008
Jul 8th, 2008
0

Re: Convert ANSI characters to character

Reputation Points: 12
Solved Threads: 7
Light Poster
RenjithVR is offline Offline
41 posts
since Mar 2008
Jul 8th, 2008
0

Re: Convert ANSI characters to character

Click to Expand / Collapse  Quote originally posted by FTProtocol ...
Well in VB6 they use Chr()

example:

C++ Syntax (Toggle Plain Text)
  1. Do
  2. sChar = Chr(GetRandomNumber())
  3. 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 == '\"')
Last edited by Ancient Dragon; Jul 8th, 2008 at 9:15 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jul 8th, 2008
0

Re: Convert ANSI characters to character

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:

C++ Syntax (Toggle Plain Text)
  1. for( sChar = rand()%256; sChar == 34; sChar = rand()%256);
Last edited by invisal; Jul 8th, 2008 at 10:25 am.
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005
Jul 8th, 2008
2

Re: Convert ANSI characters to character

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 8th, 2008
0

Re: Convert ANSI characters to character

Click to Expand / Collapse  Quote originally posted by Narue ...
>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*.
Reputation Points: 350
Solved Threads: 63
Posting Pro
invisal is offline Offline
562 posts
since Mar 2005
Jul 8th, 2008
0

Re: Convert ANSI characters to character

Yep, there was a discussion on that not so long ago on the last few posts. http://www.daniweb.com/forums/thread130222.html
Reputation Points: 1429
Solved Threads: 129
Posting Virtuoso
William Hemsworth is offline Offline
1,542 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Time and Date Display
Next Thread in C++ Forum Timeline: Conversion from int to double





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC