Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Integer to stri...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 45618 of 47995
Post > Topic >>

Integer to string conversion

by pradeep <nospam@[EMAIL PROTECTED] > Apr 28, 2008 at 10:38 PM

Hello friends:

I know some people here don't like to answer C++ questions, but I 
believe this is really about the underlying C code. Anyway I have posted 
  as well to the other group someone suggested ("comp.lang.c++") just in 
case.

I think the problem is that in my C++ class, we were taught to use cin, 
cout etc. but now I need to use the primitive C operations printf etc. 
and I don't understand exactly how they work.

I'm trying to convert an integer into a string. Here's what I'm trying, 
but when I try to output the string returned from the function, I just 
get garbage. How should I be using sprintf?

Thanks.



char *App::IntToString(int i) //doesn't really rely on cl*****
{
     char buf[2];
     char *out = buf;
     sprintf(out, "%d", i);
     return out;
}
 




 6 Posts in Topic:
Integer to string conversion
pradeep <nospam@[EMAIL  2008-04-28 22:38:37 
Re: Integer to string conversion
Keith Thompson <kst-u@  2008-04-28 17:54:19 
Re: Integer to string conversion
pradeep <nospam@[EMAIL  2008-04-29 11:22:54 
Re: Integer to string conversion
"Thomas J. Gritzan&q  2008-04-29 18:17:25 
Re: Integer to string conversion
Andy Champ <no.way@[EM  2008-04-29 23:01:42 
Re: Integer to string conversion
"Default User"   2008-04-29 17:07:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 21:23:15 CDT 2008.