Read Number from binary file - C File

C examples for File:Binary File

Description

Read Number from binary file

Demo Code

#include <stdio.h>
int main() {/*  w w  w .  j a v a  2s .  c  om*/
   FILE *intFile;
   int num;

   if ((intFile = fopen("num.bin", "wb")) == NULL) {
      printf("Cannot open file\n");
      return -1;
   }
   while (scanf("%d", &num) == 1)
      fwrite(&num, sizeof(int), 1, intFile);
   fclose (intFile);
}

Related Tutorials