/* create.c - If the file account.bin does not exist it creates it reading its content from account.dat.
              We use mmap. The balances of the accounts are all incremented by one and written out
	      to the ascii file account1.dat.
	      Run this program with only account.dat.
	      Then run it again a number of times noticing that each time the balances are
	      incremented by 1. Yet we never read account1.dat.
 */

#include <stdio.h>
#include <stdlib.h>
#include "account.h"


int main()
{
  int accounts_count = 0; /* Number of entries in accounts table */
  account_t *accounts; /* The map: account_id -> balance */
  int k;

  /* Initialization */
  
  /*   Open and read account.dat into accounts, accounts_count         */
  accounts = readin_accounts ( "account.dat", "account.bin", &accounts_count );
  /*   Increment the balances */
  for (k = 0; k < accounts_count; ++k) {
    printf ( "\t%s \t%d\n", accounts[k].id, accounts[k].balance );
    accounts[k].balance++;
  }
  /*   Write out accounts to a text file */
  write_accounts ( "account1.dat", accounts_count, accounts );

  return 0;
}










