[plug] C, bad syntax etc.

Cameron Patrick cameron at patrick.wattle.id.au
Wed Nov 20 10:43:16 WST 2002


On Wed, 20 Nov 2002 10:37:09 +0800, John Knight wrote:

| I have a file called 'temp.dat'. The file consists of something like
| this:
| Monday 23
| Tuesday 28
| Wednesday 31
| (etc.)
| 
| I have to grab all of those temperatures in the file and display the
| average  (it'll be a fixed 7 days, don't worry), so I need to ignore the
| names and just get the temperatures, using only C.

In that case, fscanf is your friend.

Try something like this:

char day[80];
int temp;

for(;;)
{
  items_read = fscanf(f, "%s %d\n", day, &temp);
  if (items_read != 2) break;
  do_stuff(temp);
}

--CP



More information about the plug mailing list