sizeof((char ****)Cminus1)
I suggest using printf() to display that value.
I suggest doing a similar thing with your sizeof() expression involving Caverages.
I also question why you're casting like this:
Code:
fwrite((char ****)Caverages, ...snip...
and this:
Code:
fread((char ****)Cminus1, ...snip..
The declared type of that arg for fwrite() and fread() is void*. Therefore, you should be casting to void*, if you're going to cast to anything. Which makes me wonder what the types of Caverages and Cminus1 actually are, that you need to cast them (or think you do).
If I've allocated memory for an array[1500][5][45][8] , how do I write to a file using fwrite?
It depends on how the array is declared, and how the memory is actually layed out.
In C, multi-dimensional array subscripting, such as array
[j] can have two distinct memory layouts:
1. If the variable is declared as an actual array, then the memory layout is row-major order in linear memory.
http://en.wikipedia.org/wiki/Row-major_order
2. If the variable is declared as an array of pointers (or as a pointer to pointers or arrays), then the memory layout is non-linear and is more like a "vector of pointers" (where vector just means a one-dimensional array). Technically, the columns (first subscript) are pointers, which point to rows (second subscript) at arbitrary memory locations. Because the columns are pointers (a vector of pointers), the memory layout is both non-linear and contains memory addresses. Those addresses will not survive a round-trip read-after-write to a file. That is, the addresses written to a file will be vacuous when read back in.
In C, any pointer can be subscripted, and every unsubscripted array reference is a constant pointer to the first element of that array.
That's probably not the most accurate summary, but it's the best I can do for now.
Please describe exactly how it doesn't work. If it does anything at all, exactly what does it do?
There are countless ways for something to not work. We can't reach into your computer and read your files, or look at your debugging history and see what didn't work, or watch how you got there. You have to be specific about your results, both the results that work and the results that don't.
http://www.mikeash.com/getting_answers.html
All in all, from everything you've posted so far, you seem unclear on exactly how C memory and arrays work. You might be better served in the long run by learning and using a language with a builtin string type, such as Perl or Python. Perl, in particular, was created for doing string-parsing and processing tasks.