Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Problem with scanf()/gets()

Reply
Thread Tools

Problem with scanf()/gets()

 
 
Walter Roberson
Guest
Posts: n/a
 
      01-03-2008
In article <flj0q3$30k5$(E-Mail Removed)>,
Richard Tobin <(E-Mail Removed)> wrote:
>In article <(E-Mail Removed)>,
> <(E-Mail Removed)> wrote:


>>I can not accept a string (without space) of length more than 127
>>whatever I do..


>>Entry is restricted by 127 characters.


>Do you mean input from a terminal? That may be limited by your
>operating system.


However,

C89 4.9.2 Streams
[...]

Environmental Limits

An implementation shall support text files with lines
containing at least 254 characters, including the terminating
new-line character. The value of the macro BUFSIZ shall be
at least 256.


As stdin is a stream and there is no exemption for stdin in the
above, an implementation that does not support lines of at least
254 characters on stdin is non-conformant.
--
"I was very young in those days, but I was also rather dim."
-- Christopher Priest
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      01-03-2008
In article <(E-Mail Removed)>,
Richard Heathfield <(E-Mail Removed)> wrote:
>Mark Bluemel said:


>> Sounds like a limit in the input buffer size provided by your operating
>> system, not a C language/library issue.


>If that's allowed by the Standard, what is the minimum such maximum input
>buffer size? If none is stated, it effectively means that even hosted
>implementations effectively don't have to provide stdin, since they can
>simply set the input buffer size to 0, rendering it impossible to read
>anything in!


C89 4.9.2 "Streams", Environmental Limits, indicates 254 minimum
for text streams (including newline.)
--
We regret to announce that sub-millibarn resolution bio-hyperdimensional
plasmatic space polyimaging has been delayed until the release
of Windows Vista SP2.
 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      01-03-2008
Richard Heathfield wrote:

> It's at times like this that I'm tempted to shout "CHRISSSSS!!!"


C has no namespaces, so that's an ambiguous reference. Also note
what Pterry has to say about multiple exclamation marks ...

I note the OP hasn't gifted us with their code, so if he's doing
something wrong, we have to use our crystal balls to see it. It
is seldom good news.

--
Tough Guide Hedgehog
"We did not have time to find out everything we wanted to know."
- James Blish, /A Clash of Cymbals/

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-03-2008
Walter Roberson said:

> In article <(E-Mail Removed)>,
> Richard Heathfield <(E-Mail Removed)> wrote:
>>Mark Bluemel said:

>
>>> Sounds like a limit in the input buffer size provided by your operating
>>> system, not a C language/library issue.

>
>>If that's allowed by the Standard, what is the minimum such maximum input
>>buffer size? If none is stated, it effectively means that even hosted
>>implementations effectively don't have to provide stdin, since they can
>>simply set the input buffer size to 0, rendering it impossible to read
>>anything in!

>
> C89 4.9.2 "Streams", Environmental Limits, indicates 254 minimum
> for text streams (including newline.)


Ah, thank you. (I looked, but couldn't find it.)

So it seems that, if the OP's report is correct, his implementation has a
conformance issue.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      01-03-2008
Chris Dollin said:

> Richard Heathfield wrote:
>
>> It's at times like this that I'm tempted to shout "CHRISSSSS!!!"

>
> C has no namespaces, so that's an ambiguous reference.


The One True Chris knows which one I mean.

> Also note
> what Pterry has to say about multiple exclamation marks ...


Yes, but at least I stopped two short of bursarity.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      01-03-2008
Richard Heathfield wrote:
> Walter Roberson said:
>
>> In article <(E-Mail Removed)>,
>> Richard Heathfield <(E-Mail Removed)> wrote:
>>> Mark Bluemel said:
>>>> Sounds like a limit in the input buffer size provided by your operating
>>>> system, not a C language/library issue.
>>> If that's allowed by the Standard, what is the minimum such maximum input
>>> buffer size? If none is stated, it effectively means that even hosted
>>> implementations effectively don't have to provide stdin, since they can
>>> simply set the input buffer size to 0, rendering it impossible to read
>>> anything in!

>> C89 4.9.2 "Streams", Environmental Limits, indicates 254 minimum
>> for text streams (including newline.)

>
> Ah, thank you. (I looked, but couldn't find it.)
>
> So it seems that, if the OP's report is correct, his implementation has a
> conformance issue.


I don't think so. The Standard requires that a text stream
be able to read a line of 254 characters, but I don't see this
as requiring that any particular input device must be capable of
generating such a line.

The C Standard is not to blame for the demise of the eighty-
column punched card.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      01-03-2008
In article <1199392278.479699@news1nwk>,
Eric Sosman <(E-Mail Removed)> wrote:
>Richard Heathfield wrote:


>> So it seems that, if the OP's report is correct, his implementation has a
>> conformance issue.


> I don't think so. The Standard requires that a text stream
>be able to read a line of 254 characters, but I don't see this
>as requiring that any particular input device must be capable of
>generating such a line.


That's a good point, and one that suggests an interesting test
for the original poster: use whatever system-dependant mechanism
is necessary in order to redirect stdin from a file, and see if
the 127 character difficulty still shows up.

We have not seen the original posters code yet, so it is still
a bit early to conclude that the difficulty is in the poster's
system's stdin handling rather than in the poster's code.
--
So you found your solution
What will be your last contribution?
-- Supertramp (Fool's Overture)
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      01-03-2008
In article <flj9n6$j4n$(E-Mail Removed)>,
Walter Roberson <(E-Mail Removed)-cnrc.gc.ca> wrote:

>>Do you mean input from a terminal? That may be limited by your
>>operating system.


> An implementation shall support text files with lines
> containing at least 254 characters, including the terminating
> new-line character. The value of the macro BUFSIZ shall be
> at least 256.


>As stdin is a stream and there is no exemption for stdin in the
>above, an implementation that does not support lines of at least
>254 characters on stdin is non-conformant.


The implementation must support 254 character lines on stdin, but you
may not be able to test that with a terminal. The ability of a
particular input device to supply long lines to a program is not
something the C standard can reasonably require.

Suppose a bar-code reader produces data in the form of a short
sequence of digits followed by a linefeed. Surely attaching this to
my computer in such a way that it can be used as standard input
doesn't render my C compiler non-conformant?

-- Richard
--
:wq
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      01-04-2008
In article <fljsa6$7e1$(E-Mail Removed)>,
Richard Tobin <(E-Mail Removed)> wrote:
>In article <flj9n6$j4n$(E-Mail Removed)>,
>Walter Roberson <(E-Mail Removed)-cnrc.gc.ca> wrote:


>>>Do you mean input from a terminal? That may be limited by your
>>>operating system.


>>As stdin is a stream and there is no exemption for stdin in the
>>above, an implementation that does not support lines of at least
>>254 characters on stdin is non-conformant.



>The implementation must support 254 character lines on stdin, but you
>may not be able to test that with a terminal. The ability of a
>particular input device to supply long lines to a program is not
>something the C standard can reasonably require.


>Suppose a bar-code reader produces data in the form of a short
>sequence of digits followed by a linefeed. Surely attaching this to
>my computer in such a way that it can be used as standard input
>doesn't render my C compiler non-conformant?


However, in such cases, it would not be the *operating system* that
limited the input size below the mandated 254, it would be the
input device's inability to produce additional characters.


It has been many a year since I last encountered a *terminal* that
limited input size -- not since the mid 80's, using CICS
(or a relative thereof) with IBM terminals that were FEP
(front end processor) programmed with input "fields" of fixed length.

--
"I was very young in those days, but I was also rather dim."
-- Christopher Priest
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-04-2008
(E-Mail Removed) writes:
> I can not accept a string (without space) of length more than 127
> whatever I do..

[...]

I don't think anybody in this thread has mentioned the problems with
gets(), probably because it was mentioned in the subject header but
not in the body of the article.

Never use gets(); it's a buffer overrun waiting to happen.
See question 12.23 in the comp.lang.c FAQ, <http://c-faq.com/>.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments