Page 1 of 1

Converting double to string in C

Posted: Sat Dec 04, 2010 7:04 pm
by Peyman
hi,
is there a way to convert double to string and return it from function like a string ?

Re: Converting double to string in C

Posted: Sat Dec 04, 2010 7:10 pm
by Blood
sprintf()

Re: Converting double to string in C

Posted: Sat Dec 04, 2010 7:13 pm
by Peyman
can you write short a example.

Re: Converting double to string in C

Posted: Sat Dec 04, 2010 9:56 pm
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

Re: Converting double to string in C

Posted: Sat Dec 04, 2010 11:39 pm
by Peyman
thanks for tips.