Ok, but I switched over to fread_word, which doesn't crash.
It used to look like this:
if (!str_cmp (word, "Mostkname"))
{
tmp = fread_string(fp);
strcpy(bfield_data.most_kills.name, tmp);
free_string(tmp);
fMatch = TRUE;
break;
}
if (!str_cmp (word, "Mostdname"))
{
tmp = fread_string(fp);
strcpy(bfield_data.most_deaths.name, tmp);
free_string(tmp);
fMatch = TRUE;
break;
}
I have switched to:
if (!str_cmp (word, "Mostkname"))
{
tmp = fread_word (fp);
strcpy(bfield_data.most_kills.name, tmp);
fMatch = TRUE;
break;
}
if (!str_cmp (word, "Mostdname"))
{
tmp = fread_word (fp);
strcpy(bfield_data.most_deaths.name, tmp);
fMatch = TRUE;
break;
}
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[email protected]>
Sent: Friday, July 12, 2002 8:03 AM
Subject: RE: reading from files, fread_string
> Could you show us lines, oh, 220 - 240 of bfio.c?
>
> -----Original Message-----
> From: Jeremy Hill [mailto:[EMAIL PROTECTED]
> Sent: Friday, July 12, 2002 1:01 AM
> To: [email protected]
> Subject: Re: reading from files, fread_string
>
>
> Hrm, As-is, this is seg faulting.
> The first attempt in bfield.dat to use tmp is Mostkname:
> #Battlefield Data
> Totalkill 100
> Totalbf 10
> Racekill 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
> Classkill 1 2 3 4 5
> Mostkname Evangelion~
> ...
>
> GDB reports:
> Program received signal SIGSEGV, Segmentation fault.
> fread_string (fp=0x80efa70) at db.c:2834
> 2834 if ((*plast++ = c) == '~')
> (gdb) bt
> ...
> #0 fread_string (fp=0x80efa70) at db.c:2834
> #1 0x08068e52 in bfield_init (fp=0x80efa70) at bfio.c:230
> (continues, but irrelevant)
> ...
> Line 230 of bfio.c is: tmp = fread_string (fp);
>
> I assign tmp as: char *tmp; at the top of bfield_init.
>
> Relatedly, Mostkname is saved to the file like this:
> fprintf(fp, "Mostkname %s~\n", bfield_data.most_kills.name);
>
> I'm not sure why it's faulting.
>
>
> ----- Original Message -----
> From: "Jeremy Hill" <[EMAIL PROTECTED]>
> To: "Michael Barton" <[EMAIL PROTECTED]>
> Cc: <[email protected]>
> Sent: Thursday, July 11, 2002 11:50 PM
> Subject: Re: reading from files, fread_string
>
>
> > Ok.
> >
> > if (!str_cmp (word, "Bestname"))
> > {
> > tmp = fread_string (fp);
> > strcpy (bfield_data.best_ratio.name, tmp);
> > free_string (tmp);
> > fMatch = TRUE;
> > break;
> > }
> >
> > Correct?
> >
> > Can I then use tmp again at a different point without running into
> trouble?
> > I.E. later:
> >
> > if (!str_cmp (word, "Mostkname"))
> > {
> > tmp = fread_string (fp);
> > strcpy(bfield_data.most_kills.name, tmp);
> > free_string(tmp);
> > fMatch = TRUE;
> > break;
> > }
> <snip>
>
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom