fread, fwrite probs 
Author Message
 fread, fwrite probs

If I had a 3 dimensional array, for example: unsigned char data[3][50][50];
how would i work out the 3rd parameter for fread and fwrite?

Please Help

--



Sat, 03 Nov 2001 03:00:00 GMT  
 fread, fwrite probs


Quote:
> If I had a 3 dimensional array, for example: unsigned char data[3][50][50];
> how would i work out the 3rd parameter for fread and fwrite?

If the type you want to write is an array (a[]), and *not* a pointer (*a),
then you can get the size, in bytes, of the entire structure using the
sizeof() operator.

        fwrite(data, 1, sizeof(data), stream);

Be careful. If data is a pointer instead of an array, then sizeof() will
return the size of the pointer, which will be 4 on most systems.

But to answer your question: multiply all the dimensions, and then
multiply by the size of the intrinsic data type (unsigned char is 1). 7500
bytes.

--
+- David Given ---------------McQ-+ "Under communism, man exploits man. Under


+- http://wired.st-and.ac.uk/~dg -+
--



Mon, 05 Nov 2001 03:00:00 GMT  
 fread, fwrite probs

The call would look like this:

fread(data, sizeof(unsigned char), 3*50*50, filefd);

Hope this helps,
Nirmal.



Quote:
> If I had a 3 dimensional array, for example: unsigned char
data[3][50][50];
> how would i work out the 3rd parameter for fread and fwrite?

> Please Help

> --


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
--



Mon, 05 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. need help with fread BIG probs

2. Please Help (fread, fwrite)

3. fwrite(), fread() portability.

4. problem with fwrite / fread

5. fopen() fseek() fread() fwrite()

6. Problem with struct/array inside a struct using fread/fwrite

7. Strange byte order using fread() and fwrite()

8. fread and fwrite

9. fread and fwrite sync

10. microsoft endian problem with fread/fwrite

11. fwrite + fread problem

12. fread/fwrite guarantees

 

 
Powered by phpBB® Forum Software