Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: sscanf question |
| Date | 2012-12-12 16:52 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <50C8FCB8.6030302@verizon.net> (permalink) |
| References | <ad54f74d-a4fe-42eb-a8e3-32a0597bd226@googlegroups.com> |
On 12/12/2012 04:29 PM, Brian O'Brien wrote: > I am trying to extract a item description and price from a line of text. > > A Cup of Coffee $1.23 > > n = sscanf(str, "%s%*[\t $]%f", item, &price); > > But how can I make "A Cup of Coffee" as a single string? How does sscanf know that I don't want just the "A" of the sentence? There's no easy way to make it accept the spaces within "A Cup of Coffee" without having it also accept the spaces between the second 'e' and the '$'. Would it be acceptable to include those spaces (and perhaps trim them off after they've been loaded into 'item'? Can you count on a '$' character always being present? If so, you could try the following: n = sscanf(str, "%[^$]$%f", item, &price); Bart's suggestion about using quotes to delimit the value of 'item' corresponds to the following: n = sscanf(str, "\"%[^\"]\"%*[\t $]%f", item, &price);
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sscanf question "Brian O'Brien" <bjobrien62@gmail.com> - 2012-12-12 13:29 -0800
Re: sscanf question "BartC" <bc@freeuk.com> - 2012-12-12 21:43 +0000
Re: sscanf question James Kuyper <jameskuyper@verizon.net> - 2012-12-12 16:52 -0500
Re: sscanf question Les Cargill <lcargill99@comcast.com> - 2012-12-12 22:14 -0600
Re: sscanf question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-12-13 14:03 +0000
Re: sscanf question falk@rahul.net (Edward A. Falk) - 2012-12-13 20:36 +0000
Re: sscanf question Prathamesh Kulkarni <bilbotheelffriend@gmail.com> - 2012-12-13 13:40 -0800
Re: sscanf question Fred K <fred.l.kleinschmidt@gmail.com> - 2012-12-13 14:31 -0800
Re: sscanf question Fred K <fred.l.kleinschmidt@gmail.com> - 2012-12-13 14:33 -0800
Re: sscanf question "BartC" <bc@freeuk.com> - 2012-12-13 22:51 +0000
Re: sscanf question Keith Thompson <kst-u@mib.org> - 2012-12-13 15:45 -0800
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-14 00:06 +0000
Re: sscanf question "BartC" <bc@freeuk.com> - 2012-12-14 02:33 +0000
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-14 03:25 +0000
Re: sscanf question "BartC" <bc@freeuk.com> - 2012-12-14 11:50 +0000
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-14 12:19 +0000
Re: sscanf question "BartC" <bc@freeuk.com> - 2012-12-14 13:38 +0000
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-14 20:40 +0000
Re: sscanf question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-12-16 03:34 -0800
Re: sscanf question falk@rahul.net (Edward A. Falk) - 2012-12-15 03:28 +0000
Re: sscanf question Les Cargill <lcargill99@comcast.com> - 2012-12-14 22:41 -0600
Re: sscanf question Keith Thompson <kst-u@mib.org> - 2012-12-15 01:25 -0800
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-15 10:26 +0000
Re: sscanf question Les Cargill <lcargill99@comcast.com> - 2012-12-15 13:24 -0600
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-15 20:15 +0000
Re: sscanf question Les Cargill <lcargill99@comcast.com> - 2012-12-15 15:33 -0600
[OT] Re: sscanf question Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-15 17:49 -0500
Re: [OT] Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-16 00:16 +0000
Re: sscanf question Barry Schwarz <schwarzb@dqel.com> - 2012-12-14 21:28 -0800
Re: sscanf question glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-12-15 08:17 +0000
Re: sscanf question Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-13 18:22 -0500
Re: sscanf question "Brian O'Brien" <bjobrien62@gmail.com> - 2012-12-13 21:13 -0800
Re: sscanf question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-12-14 12:25 +0000
csiph-web