[CODE] fread()ing problems.

From: Andrew Ritchie (object@alphalink.com.au)
Date: 02/27/99


Thankfully, I have fixed the Broken Pipe error. I simply did this by
checking if read() returned zero, and if it did I discnnected the player.
Everything seems to work fine now.

However, I have run into another difficulty. I want to load an account
structure from a binary file into memory, and into a linked list of all
accounts. However, when it does not read any data if you like. It does put
it in the linked list, but the information in the structure is blank. I'm
positive my writing to the file in binary mode was all ok... here's the code:

void load_account(char *filename)
{
   FILE *account;
   struct account_data temp, *new;
   int size;

   new = calloc(1, sizeof(struct account_data));
   sprintf(buf, "../lib/accounts/");
   sprintf(buf + strlen(buf), filename);

   if( (account = fopen(buf, "rb")) == NULL) {
      log("Cannot open account file: '%s'", buf);
      return;
   }

   fseek(account, 0L, SEEK_END);
   size = ftell(account);
   if(size) {
     if(size != sizeof(struct account_data)) {
        log("File: '%s' corrupt.", buf);
        return;
     }
     fread(&temp, sizeof(struct account_data), 1, account);
     temp.next = account_index;
     account_index = &temp;
   }
   else {
     log("Empty account file: '%s'", buf);
     return;
   }

   return;
}

If anyone could help me out here I would be very appreciative.

---
Andrew Ritchie,
object@alphalink.com.au.


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST