ok, this is frustrating me to no end. i've tried to mess with this, i've tried to just set it down and think about it, i've tried to not think about it. but i can't seem to get what's goin on here. it sometimes crashes on note send when it's the first note, but always crashes on note remove 0. i can remove any other note except note 0. here's the code:
void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote )
{
FILE *fp;
NOTE_DATA *prev;
char *to_list;
char to_new [ MAX_INPUT_LENGTH ];
char to_one [ MAX_INPUT_LENGTH ];
/*
* Build a new to_list.
* Strip out this recipient.
*/
to_new[0] = '\0';
to_list = pnote->to_list;
while ( *to_list != '\0' )
{
to_list = one_argument( to_list, to_one );
if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) )
{
strcat( to_new, " " );
strcat( to_new, to_one );
}
}
/*
* Just a simple recipient removal?
*/
if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' )
{
STRFREE( pnote->to_list );
pnote->to_list = str_dup( to_new + 1 );
return;
}
/*
* Remove note from linked list.
*/
if ( pnote == note_list )
{
note_list = pnote->next;
}
else
{
for ( prev = note_list; prev; prev = prev->next )
{
if ( prev->next == pnote )
break;
}
if ( !prev )
{
bug( "Note_remove: pnote not found.", 0 );
return;
}
prev->next = pnote->next;
}
STRFREE( pnote->text );
STRFREE( pnote->subject );
STRFREE( pnote->to_list );
STRFREE( pnote->date );
STRFREE( pnote->sender );
pnote->next = note_free;
note_free = pnote;
/*
* Rewrite entire list.
*/
fclose( fpReserve );
if ( !( fp = fopen( NOTE_FILE, "w" ) ) )
{
perror( NOTE_FILE );
}
else
{
for ( pnote = note_list; pnote; pnote = pnote->next )
{
fprintf( fp, "Sender %s~\n", pnote->sender );
fprintf( fp, "Date %s~\n", pnote->date );
fprintf( fp, "Stamp %ld\n", (unsigned long)pnote->date_stamp );
fprintf( fp, "To %s~\n", pnote->to_list );
fprintf( fp, "Subject %s~\n", pnote->subject );
fprintf( fp, "Text\n%s~\n\n", pnote->text );
}
fclose( fp );
}
fpReserve = fopen( NULL_FILE, "r" );
return;
}
and here is the remove in do_note:
if ( !str_cmp( arg, "remove" ) )
{
if ( !is_number( argument ) )
{
send_to_char( "Note remove which number?\n\r", ch );
return;
}
anum = atoi( argument );
vnum = 0;
for ( pnote = note_list; pnote; pnote = pnote->next )
{
if ( is_note_to( ch, pnote ) && vnum++ == anum )
{
note_remove( ch, pnote );
send_to_char( "Ok.\n\r", ch );
return;
}
}
does anyone see anything? i just can't seem to figure this out |