Greetings listers,
        Having a small problem writing to a file.

The code below should write the information to a comma delimited file.

void do_dump_weapons_cd( CHAR_DATA *ch, char *argument )
{
    OBJ_INDEX_DATA *pObjIndex;
    FILE *fp;
    int vnum,nMatch = 0;
    char buf[MAX_STRING_LENGTH];
    OBJ_DATA *obj;
    int level;
    int avgdam;

    fclose(fpReserve);

        fp = fopen("../../public_html/files/weap-cd.txt","w");

        fprintf(fp,"Vnum,Name,Level,Number,Dice,Avg,Resets\n");

        for (vnum = 0; nMatch < top_obj_index; vnum++)

        if ((pObjIndex = get_obj_index(vnum)) != NULL)
        {
                nMatch++;
                obj = create_object( pObjIndex, 0 );

                switch ( obj->item_type )
                {
                case ITEM_WEAPON:
                        avgdam = (((obj->value[1]*obj->value[2]) +
obj->value[1]) /2);
                        sprintf( buf, "%d,%s,%d,%d,%d,%d,%d\n",
                                                 obj->pIndexData->vnum,
                                                   obj->name,
                                                   obj->level,
                                                   obj->value[1],
                                                   obj->value[2],
                                                   avgdam,
        
obj->pIndexData->reset_num);
                        fprintf( fp, buf );
                break;
                }

        }
    fclose(fp);
    fpReserve = fopen( NULL_FILE, "r" );
    send_to_char( "Done writing files...\n\r", ch );
}

However when I run the command the mud crashes....If I remove the
obj->name portion of the sprintf, it runs just fine...can someone spot
the problem in this code?

Ive tried obj->pObjIndex->name as well, to no avail.  

Any help is appreciated. TIA

Keith Mervine
"Non Omnis Moriar"
"Growing old is mandatory, growing up is optional"
Service Management Application Developer
International Monetary Fund
[EMAIL PROTECTED]
202-623-7610


Reply via email to