Skip to main content
gamedev.net
🔒 Locked

fread + array

Started by Zeusel Jan 12, 2002 at 3:41 AM 7 replies 300+ views
Original Post
Zeusel
Zeusel
float blah[3]; fread(&blah, 4, 3, file); does this read 3 floats from a file and store them correctly? can it be used if the floats are allocated with calloc?
"be fair! ... always"Zeusel
Brannon
Brannon
No, that wont work. blah is an ''array'', but in C/C++ arrays are just pointers to buffers, so you don''t need to take the reference of blah.

if you want to read 3 floats like that, try:

  
float blah[3];

fread(blah, sizeof(float), 3, file);


You can pass a pointer to any buffer to fread().. just make sure to keep track of the proper sizes to pass as the 2nd and 3rd argument.


-Brannon
-Brannon
Beer Hunter
Beer Hunter
Unfortunately, iostreams have performance issues.
jenova
jenova
or maybe programmers should start learning how to program.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

Edited by - jenova on January 12, 2002 6:25:29 PM
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Oluseyi
Oluseyi
quote:
Original post by Beer Hunter
Unfortunately, iostreams have performance issues.

Which are in large part balanced (or outweighed?) by their ease of use and superior design. And the performance hit isn''t that severe either.

Probably the only read advantage of C-style IO is with large text formatting problems (columns, tabs, yadda yadda).
Zeusel
Zeusel
float *foo;
foo = (float*)calloc(vertexnumber * 5,4);

fread(foo, 4, vertexnumber*5, mousefile);

works perfectly
"be fair! ... always"Zeusel
GBGames
GBGames
Run! Flee! The IOStream! It''s flooding over!
Ok, just had to say that. Sorry but this post contributes nothing but bad comedy. B-)

-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel

Topic Locked

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

Sign in to reply to this topic.