What, exactly, are you trying to accomplish?
That is the real question.
Do you wish to copy the raw bytes of the double to the char
array?
That's easy (as you show). On the other hand, it's not really
useful for anything.
To be useful, you have to represent the double in some defined
format. In such cases, I would almost always recommend a text
format, say something like the "%.17g" of C. (This guarantees
that you can reread exactly the same value you wrote.) His
mention of "byte array", however, makes me wonder if he isn't
thinking of something along the lines of what Java does. For
Java compatibility, he has two solutions:
-- For maximum portability, he needs to break the floating
point down into separate sign, exponant and mantissa fields,
and insert the corresponding bits where they belong. (I
presented code to do this not too long ago here. With ldexp
and frexp, it's not that difficult. Surprisingly enough, at
least on my machine, the performance isn't that bad either.)
-- If he is willing to restrict himself to machines using IEEE
format floating point, some sort of type punning can be used
to treat the floating point as an unsigned integer of the
same size, and to output that. Formally, just about
anything involving such type punning is undefined behavior,
but practically, there will be at least one way which works
in any given implementation.