This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/fwrite.c

26 lines
496 B
C

#include <stdio.h>
struct student_data {
int student_id;
unsigned char marks[10];
};
void main()
{
FILE *fp;
struct student_data std;
int i;
fp = fopen( "file", "w" );
if( fp != NULL ) {
std.student_id = 1001;
for( i = 0; i < 10; i++ )
std.marks[ i ] = (unsigned char) (85 + i);
/* write student record with marks */
i = fwrite( &std, sizeof(std), 1, fp );
printf( "%d record written\n", i );
fclose( fp );
}
}