Tech Support > Microsoft Windows > Development Resources > Dumping lots of floats to file
Dumping lots of floats to file
Posted by Allan Bruce on July 16th, 2003


hi there,
I am trying to dump a lot of floats to a file and want to save space. Here
is my main loop which is looped several thousand times

fprintf(fptr, "%f %f %f ", normals[0][0], normals[0][1], normals[0][2]); //
output the normal
fprintf(fptr, "%f %f %f ", v1[0], v1[1], v1[2]); // output the vertice

fprintf(fptr, "%f %f %f ", normals[1][0], normals[1][1], normals[1][2]); //
output the normal
fprintf(fptr, "%f %f %f ", v2[0], v2[1], v2[2]); // output the vertice

fprintf(fptr, "%f %f %f ", normals[2][0], normals[2][1], normals[2][2]); //
output the normal
fprintf(fptr, "%f %f %f ", v3[0], v3[1], v3[2]); // output the vertice

fprintf(fptr, "%f %f %f ", normals[3][0], normals[3][1], normals[3][2]); //
output the normal
fprintf(fptr, "%f %f %f ", v4[0], v4[1], v4[2]); // output the vertice

fprintf(fptr, "\n");// go to next line

How can I output the binary values instead? At the moment I am using
approximately 240 Bytes per line, but this could be reduced to 96Bytes if I
just output the binary values. Is there a nice easy Win32 way to do this?
Thanks
Allan


Posted by Lucian Wischik on July 16th, 2003


Allan Bruce wrote:
I'm a firm believer in text-format files, since they'll be readable
easily everywhere now and in the future.
Have you thought of saving in text format, and then zipping it up?

--
Lucian


Posted by r_z_aret@pen_fact.com on July 17th, 2003


Half-joking:

To avoid machine-dependent storage without taking up quite as much
room as would straight float->character converstion, you might try a
special conversion. Around 1983, the Zeta corporation used base 36 (10
digits plus 26 letters) to store integer coordinates for their
plotters in a form that could be readily transmitted via serial cable
(that meant speed was an issue, and they needed to use less than 8
bits per "word"). Adding a few common punctuation marks could raise
the base a bit more. If privacy is an issue, this would provide a
little encryption (at least enough to eliminate accidental snooping)


On Wed, 16 Jul 2003 10:45:36 +0200, Lucian Wischik <lu.nn@wischik.com>
wrote:

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
46 Beach Street
Boston, MA 02111
www.penfact.com