Q:

How to pass "double" via write() call when it accepts only const void * type argument?

Given double temp = 6.5; how could I pass it to the UNIX write() system call:   
write(fd[1], (WTF?), 100)

fd[1] is a file descriptor.
100 is a fixed buffer size to handle large number values, just in case.

What do I put it in the middle? I've tried itoa, &temp, *temp, (char) temp, and a few other ways by googling my way to different solutions, but with no luck so far. Honestly I don't even know what type is const void *. I just know it will stop complaining if I pass a string directly such as "Hello World" to the 2nd argument.

A:

The second parameter to write is a pointer to some location in memory, and the third parameter is the number of bytes from that location in memory that you want to write to the file.  So your code would be:
double temp = 6.5;
write(fd[1], &temp, sizeof(temp));

I'm not sure if this is exactly what you want, though.  To be clear, this will write the binary representation of your double to the file.  On most platforms, that will be the following series of bytes (represented here in hexadecimal):
00 00 00 00 00 00 26 64
If this is supposed to be a text file, then you'll want to convert your number to a string first.
double temp = 6.5;
char buffer[20];
sprintf(buffer, "%g", temp);
write(fd[1], buffer, strlen(buffer));

This would write "6.5" to your file.

