Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fscanf with string and long

Tags:

c

csv

scanf

ansi-c

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?

like image 851
Fabio A. Mazzarino Avatar asked May 20 '26 22:05

Fabio A. Mazzarino


1 Answers

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

like image 179
MOHAMED Avatar answered May 23 '26 16:05

MOHAMED



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!