3

I'm trying to parse a file that another function has written with this fprintf:

fprintf(file, "DS;%s;%ld;%ld;%u\n", ds->name, ds->start, ds->period, ds->size)

I'm using this fscanf:

fscanf(file, "DS;%[^;$]s;%ld;%ld;%u", file_name, &file_start, &file_period, &file_size)

file_name is read with no problems. but file_start, file_period and file_size are always 0, even if not expected.

For exemple, the string:

DS;failures;1363978800;600;144

Is parsed like this:

  • file_name: failures (ok)
  • file_start: 0 (ko)
  • file_period: 0 (ko)
  • file_size: 0 (ko)

What am I doing wrong?

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • What is the return value? That will tell you how many conversions it did, if it's not 4 then you're not quite correct in saying that the fields are parsed to 0, they're not parsed at all (not changed by `fscanf()`). – unwind Mar 25 '13 at 13:40
  • don't know exactly the return value. But it's greater than 0 because I test the scanf for errors checking its return. – Fabio A. Mazzarino Mar 25 '13 at 14:06

1 Answers1

3

replace the string format "%[^;$]s" by this %[^;$] ==> remove the s because [] replace the s so no need any more for s

MOHAMED
  • 41,599
  • 58
  • 163
  • 268