Archived

This topic is now archived and is closed to further replies.

Zeusel

fread + array

Recommended Posts

Zeusel    122
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?

Share this post


Link to post
Share on other sites
Brannon    122
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

Share this post


Link to post
Share on other sites
jenova    122
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

Share this post


Link to post
Share on other sites
Oluseyi    2103
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).

Share this post


Link to post
Share on other sites