how to use write() to put double

G

Guest

in <AUP>


#include <unistd.h>
define BUFFSIZE 8192

char buf [BUFFSIZE];
write( STDOUT_FILENO, BUF, BUFFSIZE);

////////////////////////////////////////////

if i want to put double ,what shall i do?


double aa =11.0;
write(STDOUT_FILENO, (void *)&aa , sizeof(double));

it put &@ ....... :(
thanks
 
A

Artie Gold

in <AUP>


#include <unistd.h>
define BUFFSIZE 8192

char buf [BUFFSIZE];
write( STDOUT_FILENO, BUF, BUFFSIZE);

////////////////////////////////////////////

if i want to put double ,what shall i do?


double aa =11.0;
write(STDOUT_FILENO, (void *)&aa , sizeof(double));

it put &@ ....... :(
thanks
There is no such function as `write()' in standard C, hence your
question is off topic. Please post to a newsgroup that deals with your
particular platform. And PLEASE, RTFM!!!

--ag

[All right. A hint (and think about this): What you expect it to look
like, and why?]
 
J

Jens.Toerring


Whats said:
#include <unistd.h>

This is a non-standard header file, which probably means you're
on some UNIX-like system.
define BUFFSIZE 8192
char buf [BUFFSIZE];
write( STDOUT_FILENO, BUF, BUFFSIZE);

write() is not a standard C function but an extension of your
platform, so you should ask about this in a group discussing
programming on the system you use. If it is some kind of UNIX
comp.unix.programmer would seem to be appropriate.
if i want to put double ,what shall i do?
double aa =11.0;
write(STDOUT_FILENO, (void *)&aa , sizeof(double));
it put &@ ....... :(

If you want the number written out in a form like "11.000000" use
fprintf(). Functions like fwrite() (which probably is the thing
most nearly related to write()) output the binary representation
of the double, not the result of a conversion to a string.

Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top