0

I'm developing a C project for school, and I have to read a CSV file. My problem is that some values include spaces, and that's why I can't use fscanf(file, "%s", string);.

I've tried this : fscanf(file, "%[0-9A-Za-z ,.-]", string);, fscanf(file, "%[0-9A-Za-z ,.\-]", string); and fscanf(file, "%[0-9A-Za-z ,.--]", string); but none of these are working.

Can anyone help me ?

  • 2
    Use `fgets()`.. – kiran Biradar Jun 24 '20 at 09:54
  • Does it stop with \r? – Benoit Bouckaert Jun 24 '20 at 09:56
  • You can't parse a CSV with `scanf` because fields can be quoted. It's not difficult to write a lexer from scratch, and that's probably what I'd do. But that said, can you provide an example string that your scanf fails to read? Maybe a minimal reproduction, including a hard-coded string to parse, and some example program that reads it? – Paul Hankin Jun 24 '20 at 10:00

0 Answers0