forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert number to a string

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Slopey



Joined: 31 Jul 2005
Posts: 24

PostPosted: Wed Jul 26, 2006 9:07 am    Post subject: Convert number to a string Reply with quote

Hi All,

What's the easiest way to convert a number to a string (for example an integer?) in C/C++?

In the past Ive used itoa but I believe thats non-standard.

Thanks in advance - it's been a while since I've done any C/C++ and this one has complete escaped me - it's also missing from my books :/

Cheers,
S.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Jul 26, 2006 9:20 am    Post subject: Reply with quote

Either use itoa as you said, or do the dirty way with sprintf.

Code:

int i = 5023;
char number[32];
snprintf(number,32,"%i",i);
Back to top
View user's profile Send private message Visit poster's website
ADePSP



Joined: 13 Jul 2006
Posts: 58

PostPosted: Wed Jul 26, 2006 9:59 am    Post subject: Reply with quote

Raphael wrote:
Either use itoa as you said, or do the dirty way with sprintf.

Code:

int i = 5023;
char number[32];
snprintf(number,32,"%i",i);

Why is "sprintf" dirty...? Really, i'm new and I use this...?

Code:
  char buffer[200];
  float num = 20.39999999;

  sprintf(buffer,"Why is this wrong...? Does this float look nice %.02...?",num);

If there is something wrong with that please tell us...?

ADe

P.S. Apart from declaring more bytes for the char than were needed... :D
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Jul 26, 2006 11:08 am    Post subject: Reply with quote

ADePSP wrote:

Why is "sprintf" dirty...? Really, i'm new and I use this...?

Well, it's not really dirty, I just called it that in this case, as it needs the extra line to declare your buffer ;)

ADePSP wrote:

Code:
  char buffer[200];
  float num = 20.39999999;

  sprintf(buffer,"Why is this wrong...? Does this float look nice %.02...?",num);

If there is something wrong with that please tell us...?

well, I think it should be %.02f but other than that it's perfectly fine
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group