Well, I know you got that other response that gives you a working function, but yes, you did have a few problems, one that wasn't mentioned, was your use of nMatch. It would only increase if the object existed. You -don't want to do that ;) See, if your on your 100th weapon, but its vnum 32 000, then you got a problem, eh? Especially if its going for another 32 668 or whatever the number is.

Davion




From: "Mervine, Keith" <[EMAIL PROTECTED]>
To: <[email protected]>
Subject: Problem with writing to a file
Date: Mon, 14 Apr 2003 16:34:30 -0400

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


--
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail


Reply via email to