Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #149354
| From | Andrey Tarasevich <andreytarasevich@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Scanf and Comma Delimiter |
| Date | 2020-01-22 11:45 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <r0a8od$ijj$1@dont-email.me> (permalink) |
| References | <r07n7p0d1d@news3.newsguy.com> |
On 1/21/2020 12:34 PM, F Russell wrote:
> I've always wondered why the scanf() function cannot accept
> a comma as a delimiter. Reading CSV files would be so much
> easier without having to write or use a special parser.
>
> Is there some reason why a comma delimiter is not accepted
> by scanf()?
>
Um... What are you talking about? `scanf` has absolutely no problems
working with comma delimiter.
`scanf` is not very well suited for parsing CSV files mostly because
`scanf` format specifiers don't support empty sequences, i.e. when a
format specifier discovers that it matches an empty sequence, it
triggers an "error" and aborts the whole `scanf`. This issue applies
specifically to the `%[]` format.
This is something one should keep in mind when parsing CSV sequences like
value1,,,value2,value3,,value4
i.e. sequences where delimiters might be densely "packed" to designate
empty fields. But even that issue can be worked around, if one knows
what one's doing.
--
Best regards,
Andrey Tarasevich
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
Scanf and Comma Delimiter F Russell <fr@random.info> - 2020-01-21 20:34 +0000
Re: Scanf and Comma Delimiter Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-21 21:40 +0100
Re: Scanf and Comma Delimiter chad <cdalten@gmail.com> - 2020-01-21 13:04 -0800
Re: Scanf and Comma Delimiter Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-21 21:34 +0000
Re: Scanf and Comma Delimiter Anton Shepelev <anton.txt@g{oogle}mail.com> - 2020-01-22 13:37 +0300
Re: Scanf and Comma Delimiter gazelle@shell.xmission.com (Kenny McCormack) - 2020-01-22 11:46 +0000
Re: Scanf and Comma Delimiter Anton Shepelev <anton.txt@g{oogle}mail.com> - 2020-01-22 15:25 +0300
Re: Scanf and Comma Delimiter Bart <bc@freeuk.com> - 2020-01-22 14:02 +0000
Re: Scanf and Comma Delimiter Bart <bc@freeuk.com> - 2020-01-22 20:13 +0000
Re: Scanf and Comma Delimiter Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-22 15:00 +0000
Re: Scanf and Comma Delimiter Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-01-29 11:10 -0500
Re: Scanf and Comma Delimiter scott@slp53.sl.home (Scott Lurndal) - 2020-01-21 20:51 +0000
Re: Scanf and Comma Delimiter Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-21 21:31 +0000
Re: Scanf and Comma Delimiter James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-22 00:03 -0500
Re: Scanf and Comma Delimiter Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-01-21 13:43 -0800
Re: Scanf and Comma Delimiter F Russell <fr@random.info> - 2020-01-21 22:32 +0000
Re: Scanf and Comma Delimiter richard@cogsci.ed.ac.uk (Richard Tobin) - 2020-01-21 23:20 +0000
Re: Scanf and Comma Delimiter Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-01-21 23:15 -0800
Re: Scanf and Comma Delimiter James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-22 00:30 -0500
Re: Scanf and Comma Delimiter Andrey Tarasevich <andreytarasevich@hotmail.com> - 2020-01-22 11:45 -0800
csiph-web