Converting Int to Const Char

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2005
Posts: 10
Reputation: bballmitch is an unknown quantity at this point 
Solved Threads: 0
bballmitch bballmitch is offline Offline
Newbie Poster

Converting Int to Const Char

 
0
  #1
Aug 5th, 2005
How do i convert an int to a const char?
also, how do i convert a string to a const char?

thanks for all the help.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 164
Reputation: Stoned_coder is an unknown quantity at this point 
Solved Threads: 5
Stoned_coder Stoned_coder is offline Offline
Junior Poster

Re: Converting Int to Const Char

 
0
  #2
Aug 5th, 2005
int to const char....
int a=12345;
const char c = a &0xff;

string to const char....
string s("some bollux");
const char c = s[0];

I suspect you meant const char* as the above examples although correct will probably be not what you intended.

string to const char* ....

string s("some bollux");
// then when you need the const char* from this you call strings member func c_str().
if (strcmp(s.c_str(),"some bollux")== 0)
{}

int to const char* ....

int a = 12345;
ostringstream os;
os<<a;
string s = a.str();
if (strcmp(s.c_str(),"12345")== 0)
{}

etc.
Reply With Quote Quick reply to this message  
Reply

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




Views: 10958 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC