Thursday, 6 March 2014

Reading and Writing Data to Binary file

=========
Writing Data
=========

#include <stdio.h>

void main()
{
   FILE *bin;

   int s;
   s=123;
  bin = fopen("ASIM.txt", "wb");
  fwrite(&s, sizeof(s),5,bin);
  fclose(bin);
}


==========
Reading Data
==========

#include<stdio.h>
#include<conio.h>
void main()
{
   FILE *bin;

  int s;
  bin = fopen("ASIM.txt", "rb");
  fread(&s, sizeof(s),5,bin);
  printf("%d",s);
  getch();
  fclose(bin);
}

No comments:

Post a Comment