Skip to main content
gamedev.net
🔒 Locked

files

Started by SomebodySomeone 3 replies 300+ views
Original Post
SomebodySomeone
SomebodySomeone
hi i have a map-file (like the one in the tut, but it has quads). i know that i can write with fputs a string into the file. but i need to write floats into file. does anybody know the function??? i need it for the map editor.
Tirisfal
Tirisfal
The fwrite(const void *buffer, size_t size, size_t count, FILE* stream) function is probably what you''re looking for.

To write a float to a file with this function you need code that goes something like this:


float myFloat;

// open the file for binary write
FILE* pFile = fopen("filename.dat","wb");

// write the float
fwrite(&myFloat,sizeof(float),1,pFile);

// close our file
fclose(pFile);



Hope this helps,
Matt

Microsoft Development Theory-
It compiles? Ship it!!
Microsoft Development Theory-It compiles? Ship it!!
SomebodySomeone
SomebodySomeone
thx
but i want to save it to a normal .txt - file.
now, when i save it and then look at the file, there are just weird symbols.
does anybody know a other way????
the Dealy Lama
the Dealy Lama
i suppose you could use fprintf() and fscanf()

  
// to write

FILE *file = fopen("filename.dat","w");
fprintf(file,"%f",myFloat);
fclose(file);
//

//

// to read

FILE *file = fopen("filename.dat","r");
fscanf(file,"%f",&myFloat);
fclose(file);


Gruad the Dealy Lama

"What sounds to you like a big bloat of trashy old noise
is in fact the brilliant music of a genius--myself" ~ Iggy Pop
=======================================Matt Welch"What sounds to you like a big bloat of trashy old noiseis in fact the brilliant music of a genius--myself" ~ Iggy Pop

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.