[CODE] Allocating an array of strings. Funky.

From: Chuck Reed (creed@I-55.COM)
Date: 05/14/98


Ok, I'm writing some clan code and I have run into a problem.  I have set
up a struct of

struct clan_info {
   int owner;
   int members;
   int gold;
   int number;
   char name[25];
}

and I want to set up a clan_index when the mud boots with an array of
struct clan_info like so

struct clan_info *clan[number of clans];

So I can access clan[2].gold at any point in the code and these structs
will be in place.  I'm not good with memory allocation or file
manipulation, so bear with me here.  What I've run into is this, I'm
reading clan stats from files and I want to assign values like so:

void clan_boot(void)
{
   int number_of_clans = 0, i = 0;
   char to_open[15];
   FILE *index, *current;
   struct clan_info *clans[];

   if(!(index = fopen(INDEX_FILENAME, "r"))) {
      log("Error - No clan index exists!");
      ERROR_IN_CLAN_BOOT = TRUE;
      exit(1);
     }

   while !feof(index) {
      fscanf(index, "%s\n", to_open);
      if(!(current = fopen(to_open, "r"))) {
        log("Error - Clan index contains missing clan file.");
        ERROR_IN_CLAN_CODE = TRUE;
        exit(1);
       }
      fscanf(current, "%s\n", temp_owner);
      fscanf(current, "%s\n", temp_name);
      ... etc etc
      clan[i].owner = atoi(temp_owner);
      clan[i].name = str_dup(temp_name);
      ... etc etc
      number_of_clans++;
     }

---------------------------------------
Chuck Reed      | Ash of Dark Horizon |
master@i-55.com | dh.gator.net 6001   |
---------------------------------------


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



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