Converting double to string in C

For everything that's not in any way related to PureBasic. General chat etc...
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Converting double to string in C

Post by Peyman »

hi,
is there a way to convert double to string and return it from function like a string ?
Sorry for my bad english.
User avatar
Blood
Enthusiast
Enthusiast
Posts: 161
Joined: Tue Dec 08, 2009 8:34 pm
Location: United Kingdom

Re: Converting double to string in C

Post by Blood »

sprintf()
C provides the infinitely-abusable goto statement, and labels to branch to. Formally, the goto is never necessary, and in practice it is almost always easy to write code without it. We have not used goto in this book. -- K&R (2nd Ed.) : Page 65
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Re: Converting double to string in C

Post by Peyman »

can you write short a example.
Sorry for my bad english.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Converting double to string in C

Post by Mistrel »

Don't ever use sprintf(). Use snprintf(), introduced in ISO C99. Also, you can use string streams in C++.

Examples here:

http://libslack.org/manpages/snprintf.3.html

See Wikipedia for a description of buffer overflow with sprintf():

http://en.wikipedia.org/wiki/Printf#sprintf
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Re: Converting double to string in C

Post by Peyman »

thanks for tips.
Sorry for my bad english.
Post Reply