Couple of problems there...
You weren't checking whether or not the file was actually opened for writing 
-- could have caused a crash.
The vnum loop was probably right, but just running through every possible vnum 
is pretty fast anyway and less vulnerable to problems in other parts of the 
code.
No reason to create an instance of every obj since the index has all the 
information, and if you do create them, you really need to free them..!  That 
is a huge old memory leak.
sprintf to a buf then fprintf the buf to a file?  Just fprintf the info to the 
file.

void do_dump_weapons_cd( CHAR_DATA *ch, char *argument )
{
  OBJ_INDEX_DATA *obj;
  FILE *fp;
  int vnum;

  fclose(fpReserve);
  fp = fopen("../../public_html/files/weap-cd.txt","w");
  if (!fp)
  {
    send_to_char("Unable to open file for writing.\n\r", ch);
    return;
  }
  fprintf(fp,"Vnum,Name,Level,Number,Dice,Avg,Resets\n");
  for (vnum = 0; vnum < 32768; vnum++)
    if ((obj = get_obj_index(vnum)) != NULL)
    {
      if (obj->item_type == ITEM_WEAPON)
      {
          fprintf(fp, "%d,%s,%d,%d,%d,%d,%d\n",
            obj->vnum,
            obj->name,
            obj->level,
            obj->value[1],
            obj->value[2],
            (((obj->value[1]*obj->value[2]) +
              obj->value[1]) /2),
            obj->reset_num);
      }
    }
  fclose(fp);
  fpReserve = fopen(NULL_FILE, "r");
  send_to_char("Done writing files...\n\r", ch);
}

So there you go.. I don't know what was causing your crash, but I know that 
this one works.

--Palrich.


Reply via email to