473,379 Members | 1,184 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Problem with scanf()/gets()

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

Entry is restricted by 127 characters.

I have declared an array of size more than 200.
or
I have used dynamic memory allocation.

But the echo is stopped
Jan 3 '08 #1
19 2119
su**************@yahoo.co.in wrote:
I can not accept a string (without space) of length more than 127
whatever I do..

Entry is restricted by 127 characters.

I have declared an array of size more than 200.
or
I have used dynamic memory allocation.

But the echo is stopped
Sounds like a limit in the input buffer size provided by your operating
system, not a C language/library issue.
Jan 3 '08 #2
Mark Bluemel said:
su**************@yahoo.co.in wrote:
>I can not accept a string (without space) of length more than 127
whatever I do..

Entry is restricted by 127 characters.

I have declared an array of size more than 200.
or
I have used dynamic memory allocation.

But the echo is stopped

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!

In other words, I think you're wrong - if the implementation is truly
behaving as described, it sounds non-conforming to me. But I will
cheerfully point out that I'm not sure of my ground.

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

--
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
Jan 3 '08 #3
In article <1t******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>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!
That would be contrary to the requirement to allow at least one
character of ungetc pushback.
--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
Jan 3 '08 #4
On Jan 3, 6:24*am, subratasinha2...@yahoo.co.in wrote:
I can not accept a string (without space) of length more than *127
whatever I do..

Entry is restricted by 127 characters.

I have declared an array of size more than 200.
or
I have used dynamic memory allocation.

But the echo is stopped
Without showing us the code, there is no way we can find the problem.
--
Fred Kleinschmidt
Jan 3 '08 #5
Walter Roberson said:
In article <1t******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>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!

That would be contrary to the requirement to allow at least one
character of ungetc pushback.
No, it wouldn't, because of the "as if" rule - you'd never be able to tell
that it hadn't been pushed back! :-)

--
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
Jan 3 '08 #6
In article <2c**********************************@i29g2000prf. googlegroups.com>,
<su**************@yahoo.co.inwrote:
>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.

-- Richard
--
:wq
Jan 3 '08 #7
Richard Heathfield wrote:
Mark Bluemel said:
>su**************@yahoo.co.in wrote:
>>I can not accept a string (without space) of length more than
127 whatever I do..

Entry is restricted by 127 characters.

I have declared an array of size more than 200.
or
I have used dynamic memory allocation.

But the echo is stopped

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!
Where does it say that stdin has to be editable on input?

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Jan 3 '08 #8
In article <pe*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>Walter Roberson said:
>In article <1t******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>>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!
>That would be contrary to the requirement to allow at least one
character of ungetc pushback.
>No, it wouldn't, because of the "as if" rule - you'd never be able to tell
that it hadn't been pushed back! :-)
You are allowed to ungetc() a character that has not actually
been read, and when you read from that stream you must get that
character. Therefore stdin must be provided, even if the
functionality is only the equivilent of having stdin connected
to /dev/null
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
Jan 3 '08 #9
On Jan 3, 6:24 am, subratasinha2...@yahoo.co.in wrote:
I can not accept a string (without space) of length more than 127
whatever I do..

Entry is restricted by 127 characters.

I have declared an array of size more than 200.
or
I have used dynamic memory allocation.

But the echo is stopped

what OS, what compiler?

Jan 3 '08 #10
In article <fl***********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>In article <2c**********************************@i29g2000prf. googlegroups.com>,
<su**************@yahoo.co.inwrote:
>>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
Jan 3 '08 #11
In article <1t******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>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.
Jan 3 '08 #12
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/

Jan 3 '08 #13
Walter Roberson said:
In article <1t******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>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
Jan 3 '08 #14
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
Jan 3 '08 #15
Richard Heathfield wrote:
Walter Roberson said:
>In article <1t******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>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.

--
Er*********@sun.com

Jan 3 '08 #16
In article <fl**********@canopus.cc.umanitoba.ca>,
Walter Roberson <ro******@ibd.nrc-cnrc.gc.cawrote:
>>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
Jan 3 '08 #17
In article <fl**********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.ukwrote:
>In article <fl**********@canopus.cc.umanitoba.ca>,
Walter Roberson <ro******@ibd.nrc-cnrc.gc.cawrote:
>>>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
Jan 4 '08 #18
su**************@yahoo.co.in 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) <ks***@mib.org>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 4 '08 #19
In article <fl**********@canopus.cc.umanitoba.ca>,
Walter Roberson <ro******@ibd.nrc-cnrc.gc.cawrote:
>>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.
The location of the boundary between operating system and device is
irrelevant to the conformance of the C implementation. if you contrive
to provide a long line on standard input, the C system will handle it.
That you can't do that by some particular method is none of the C
standard's business.

Do you think the compiler would be non-conformant if there weren't any
terminal devices?

-- Richard
--
:wq
Jan 4 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
by: Teh Charleh | last post by:
OK I have 2 similar programmes, why does the first one work and the second does not? Basically the problem is that the program seems to ignore the gets call if it comes after a scanf call. Please...
18
by: Radith | last post by:
HI all; I have created a program just to get an understanding of strcpy. (still an amateur developer). I use scanf("%s", &first) in order to get the input to the variable first (which is char...
185
by: Martin Jørgensen | last post by:
Hi, Consider: ------------ char stringinput ..bla. bla. bla. do {
1
by: Gaijinco | last post by:
Hi! I was coding something which had some lines like these: int main(){ int n; scanf("%d",&n); fflush(stdin); int* ans = new int; int idx=0;
4
by: Sudip | last post by:
I'm new in c programming. I am writing a program which reads the ID3 V1 tag from a mp3 file and edits it. But everytime i try to take inputs , the first character of my album contains 0. So, it...
20
by: Xavoux | last post by:
Hello all... I can't remind which function to use for safe inputs... gets, fgets, scanf leads to buffer overflow... i compiled that code with gcc version 2.95.2, on windows 2000 char tmp0 =...
1
by: ankit0288 | last post by:
I am new here and decided to join a forum in order to help me out with my programming difficulties. Hope i get a reply soon on this I have been experiencing problems in using the gets() command in...
18
by: Vijaykumar Dave | last post by:
I have a program for base X power N as under. The problem is that when the range specified in loop is given it works well, but when any character is pressed, it goes to infinite loop. Second...
11
by: aljaber | last post by:
hi, i am facing a problem with my program output here is the program /*********************************************\ * CD Database * * ...
3
by: Vasu | last post by:
Hi! Can anybody there help me in analysis of the following code, which is a structure of customer's details, asks user to fill in the no. of customers and then their details. When I put in no. of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.