Re: sprintf function
From: Martin Ambuhl (mambuhl_at_earthlink.net)
Date: 02/08/04
- Next message: Old Wolf: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Previous message: Mike Wahler: "Re: Cannot create file for write"
- In reply to: Earth: "sprintf function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 08 Feb 2004 20:52:41 GMT
Earth wrote:
...
> I have written a testing program to try the sprintf fuction and expect
> the output is 1.234. However, the output shows nothing.
...
> #include <stdio.h>
> char* toString(double d)
> {
> char buffer[9];
> sprintf(buffer, "%lf", d);
> return buffer;
> }
>
> main()
> {
> printf("%s\n", toString(1.234));
> }
But this code ...
#include <stdio.h>
char *toString(double d)
{
static char buffer[9];
sprintf(buffer, "%lf", d);
return buffer;
}
int main(void)
{
printf("%s\n", toString(1.234));
return 0;
}
Has this output:
1.234000
Notice the difference?
-- Martin Ambuhl
- Next message: Old Wolf: "Re: efficiency concern: when to really use unsigned ints and when not to"
- Previous message: Mike Wahler: "Re: Cannot create file for write"
- In reply to: Earth: "sprintf function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|