Code Snippets C

#include
#include
int main(void)
{
FILE *filep;
int i;
/* open file for output */
if((filep = fopen("myfile.txt", "wb"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
i = 100;
if(fwrite(&i, 2, 1, filep) != 1) {
printf("Write error occurred.\n");
exit(1);
}
fclose(filep);
/* open file for input */
if((filep = fopen("myfile", "rb"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
if(fread(&i, 2, 1, filep) != 1) {
printf("Read error occurred.\n");
exit(1);
}
printf("i is %d", i);
fclose(filep);
return 0;
}