Mervine, Keith wrote:
Greetings,
I have written a small function to list all skills and levels
the classes receive the skills at in a comma delimited format.
void do_skillcd(CHAR_DATA *ch,char *argument)
{
char arg1[MIL];
char buf[MSL];
int i, sn, skill,class = 0;
FILE *fp;
fclose( fpReserve );
fp = fopen("../data/skillcd.txt", "w" );
for (sn = 0; sn < MAX_SKILL; sn++)
{
sprintf(buf,"%s",skill_table[sn].name);
fprintf(fp, buf);
for (i=0; i < MAX_CLASS; i++)
{
sprintf(buf,",%d",skill_table[sn].skill_level[i]);
fprintf(fp, buf);
}
sprintf(buf,"\n");
fprintf(fp,buf);
}
send_to_char("Done writing\n\r",ch);
You forgot to close your open file pointer.....
fclose( fp );
> fpReserve = fopen( NULL_FILE, "r" );
return;
}
Is there something wrong with this code? What am I missing?
fclose also flushes the buffers. Which is most likely your problem, the
buffers aren't being flushed so the data is hanging in limbo. You also
are going to create major issues for yourself if you run this program
many times in a row. As each time it will open a new pointer for file
i/o, and you only have a limited amount per process...
Fraktyl