Advertisement
FollowTheMedia

Initializing a simple empty binary file

Jan 6th, 2013
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct clientData
  4. {
  5.   int accountNum;
  6.   char lastName[15];
  7.   char firstName[10];
  8.   double balance;
  9. };
  10. int main (void){
  11.  FILE *cfPtr;
  12.  int i;
  13.  struct clientData client = {0, "", "", 0.0};
  14.  if ((cfPtr=fopen("credit.dat", "wb")) == NULL){
  15.    printf("File couled not be opened\n");
  16.  }
  17.  else {
  18.    for(i=0;i<100;i++){
  19.      printf("Initializing accountno %d\n",i);
  20.      client.accountNum=i+1;
  21.      fwrite(&client, sizeof (struct clientData), 1, cfPtr);
  22.    }
  23.    fclose(cfPtr);
  24.  }
  25.  
  26.  return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement