If you want to write to the file then you'll need to use a function that does this, fwrite for example. Here's some quickie code that you can modify to get the results you need:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Record
{
char name[80];
} static sRec[3];
int main ( void )
{
FILE *fp;
/* Input data into the struct here */
if ( ( fp = fopen ( "tst.txt", "wb" ) ) != NULL ) {
fwrite ( sRec, sizeof ( struct Record ), (size_t)3, fp );
fclose ( fp );
}
/* Test the write by reading it back from the file */
if ( ( fp = fopen ( "tst.txt", "rb" ) ) != NULL ) {
fread ( sRec, sizeof ( struct Record ), (size_t)1, fp );
fclose ( fp );
}
return EXIT_SUCCESS;
}
>fflush(stdin);
Why does everyone do this? The behavior is undefined, never fflush input streams.
-Prelude