Thanks to all that replyed.

Richard Ivanwich

----------
> From: Henrik Nordstrom <[EMAIL PROTECTED]>
> To: Richard Ivanowich <[EMAIL PROTECTED]>
> Cc: linux c programming <[EMAIL PROTECTED]>
> Subject: Re: Reading file in a structure
> Date: Sunday, September 13, 1998 3:12 PM
> 
> Richard Ivanowich wrote:
> > 
> > The file is just a plain test file like so
> > 
> > ---
> > joe             30
> > larry           20
> > moe             50
> > ---
> 
> Then the simplest parser is
> 
>  char user[10+1]; /* +1 for terminating null */
>  int number;
>  while (fscanf(fp, "%10s %d\n", user, &number) == 2)
>  {
>    /* Do something with user & number */
>  }
> 
> But if you want to provide intelligent error handling & reporting then
> the approach shown by Glynn using fgets and sscanf is more appropriate.
> 
> If you'd like to allow spaces in the username then you could use %10c
> instead of %10s, or build a more complex parser.
> 
> How to compare the two files depens on if the files are sorted or not.
> If the files are sorted then you can read both files and compare one
> record at a time. If the files are unsorted then you need to store one
> of them in memory (perferably sorted in a tree or hash structure if the
> number of records are large).
> 
> ---
> Henrik Nordstr�m

Reply via email to