You should not put a hardcode number in the function call-- you should always use the 'sizeof' statement.
prototype:
----------
fwrite(void *buffer,size_t elem_size,int num_elem,FILE *stream);
buffer = your buffer filled with data-- this can be a single struct, or a single-dim'd array of struct of like-size.
elem_size = size of individual structure. If you are writing an array of structs, this could simply be the size of the entire array.
num_elem = number of individual structures/elements. If you were writing an entire array, then this could just be a one, so long as 'elem_size' is as big as all the structures in the array.
stream = record for the file control block.
---
So, instead of using fwrite the way you do, rewrite it like so:
Code:
typedef struct
{
int yearMade; /* when video made (c) */
char actors[5][35]; /* actor names */
long runTime; /* running time, minutes */
char rating[6]; /* movie rating */
}videoStruc;
int main(void)
{
videoStruc video; /* declare vars */
FILE tfile = 0L;
...
fwrite(&video,sizeof(videoStruc),1,tfile);
...
return(0);
}
fopen() is very nearly the same, just moving data in a different direction. In both cases, you should position the file pointer prior to reading/writing so that it is where you expect it. You should also be checking for errors.
enjoy.