Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | BartC <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: sscanf error checking |
| Date | 2016-12-14 20:43 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o2sar2$7mq$1@dont-email.me> (permalink) |
| References | <o2rp71$3e7$1@dont-email.me> <o2rqur$5t5$1@news.xmission.com> <o2s0o1$fb$1@dont-email.me> <871sxa70kq.fsf@bsb.me.uk> |
On 14/12/2016 19:49, Ben Bacarisse wrote:
> BartC <bc@freeuk.com> writes:
>>> status = sscanf(str,"%lf%n",&x,&n);
>>>
>>> printf("Status = %d, n = %d, length = %lu\n",status,n,strlen(str));
>>> printf("X = %f\n",x);
>>> }
>>>
>>> And you can see that the value of 'n' and the length of the string are not equal.
>>> That indicates that something went wrong.
>>
>> OK, thanks.
>
> (It's slightly simpler to test that str[n] is 0.)
(I already know the length of the string.)
> <snip>
>> (Actually, up to now I've only used sscanf in one place and that /was/
>> with a "%lf%n" format, but that was to be able to step to the next
>> item within a larger string.)
>
> The code that (I thought) you wrote for your line input exercise has
> sscanf(s,"%lf",&x) in the strtofloat function.
Yes it was. But my interpreter apparently uses %lf%n to read a float
then step along the buffer.
(I posted an example in that language today that used 'readln @f,a,b,c
to read a line of input then read 3 floats. Actually it reads ints
unless otherwise specified. I'm changing that so that each read item is
set to an int, float or string according to what is encountered. That
will make my example accurate.
Otherwise the example would have to be 'readln @f,a:"r",b:"r",c:"r"
which is not quite as short and sweet compared to the C. However the
change makes emulating that in a static language harder.)
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sscanf error checking BartC <bc@freeuk.com> - 2016-12-14 15:42 +0000
Re: sscanf error checking John Gordon <gordon@panix.com> - 2016-12-14 15:58 +0000
Re: sscanf error checking Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-14 11:14 -0500
Re: sscanf error checking gazelle@shell.xmission.com (Kenny McCormack) - 2016-12-14 16:11 +0000
Re: sscanf error checking BartC <bc@freeuk.com> - 2016-12-14 17:51 +0000
Re: sscanf error checking gazelle@shell.xmission.com (Kenny McCormack) - 2016-12-14 18:09 +0000
Re: sscanf error checking Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 19:49 +0000
Re: sscanf error checking BartC <bc@freeuk.com> - 2016-12-14 20:43 +0000
Re: sscanf error checking Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 16:40 +0000
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-14 09:34 -0800
Re: sscanf error checking Robert Wessel <robertwessel2@yahoo.com> - 2016-12-14 14:52 -0600
Re: sscanf error checking supercat@casperkitty.com - 2016-12-15 07:24 -0800
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-15 11:26 -0800
Re: sscanf error checking Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 15:35 -0800
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-15 16:28 -0800
Re: sscanf error checking Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 16:37 -0800
Re: sscanf error checking supercat@casperkitty.com - 2016-12-15 16:38 -0800
Re: sscanf error checking raltbos@xs4all.nl (Richard Bos) - 2016-12-15 20:20 +0000
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-15 12:33 -0800
sscanf error checking asetofsymbols@gmail.com - 2016-12-16 01:49 -0800
sscanf error checking asetofsymbols@gmail.com - 2016-12-16 01:53 -0800
csiph-web