Convert ANSI characters to character

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 99
Reputation: FTProtocol has a little shameless behaviour in the past 
Solved Threads: 1
FTProtocol FTProtocol is offline Offline
Junior Poster in Training

Convert ANSI characters to character

 
0
  #1
Jul 8th, 2008
Well in VB6 they use Chr()

example:

  1. Do
  2. sChar = Chr(GetRandomNumber())
  3. Loop While sChar = Chr(34)

Just wondering if there is a similar function in c++?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 41
Reputation: RenjithVR is an unknown quantity at this point 
Solved Threads: 7
RenjithVR RenjithVR is offline Offline
Light Poster

Re: Convert ANSI characters to character

 
0
  #2
Jul 8th, 2008
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,454
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1476
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Convert ANSI characters to character

 
0
  #3
Jul 8th, 2008
Originally Posted by FTProtocol View Post
Well in VB6 they use Chr()

example:

  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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Convert ANSI characters to character

 
0
  #4
Jul 8th, 2008
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:

  1. for( sChar = rand()%256; sChar == 34; sChar = rand()%256);
Last edited by invisal; Jul 8th, 2008 at 10:25 am.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,740
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: Convert ANSI characters to character

 
2
  #5
Jul 8th, 2008
>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'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Convert ANSI characters to character

 
0
  #6
Jul 8th, 2008
Originally Posted by Narue View Post
>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*.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,442
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 118
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: Convert ANSI characters to character

 
0
  #7
Jul 8th, 2008
Yep, there was a discussion on that not so long ago on the last few posts. http://www.daniweb.com/forums/thread130222.html
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC