473,473 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Where is error checking on fgets() addressed in FAQ?

I recently challenged one of my students to figure out a way to determine if
fgets() actually received the entire contents of the input string. When he
was having trouble figuring it out even after I recommended he look
carefully at the difference between the two cases when the input was short
enough and when the input was too long, I suggested he look at the FAQ for
this newsgroup. He came back and said he couldn't find anything, so I went
and looked and, although I thought I remembered seeing it there before, I
couldn't find anything either.

Could someone provide the topic number that deals with trapping this
occurance (if one exists)?

I found 12.20 ( http://www.eskimo.com/~scs/C-faq/q12.20.html ) right away
and this seems a natural spot to place a link to the topic that actually
goes into this issue at length.

Is there a version of the FAQ someplace that is searchable? Or, if the
eskimo site is searchable, could someone explain how? I haven't downloaded
the ASCII version and I'm assuming I can search it, but I can't find an
on-line version of it which, from a utility standpoint, is reasonably
important if I'm going to get students to use it since they move from
machine to machine a lot.

TIA


Nov 14 '05 #1
7 1750

"William L. Bahn" <wi*****@toomuchspam.net> wrote in message
I recently challenged one of my students to figure out a way to
determine if fgets() actually received the entire contents of the input
string.
Could someone provide the topic number that deals with trapping
this occurance (if one exists)?

We had a huge row about this a few years ago and the FAQ maintainer still
hasn't come round to admitting that I was right.
Nov 14 '05 #2

"Malcolm" <ma*****@55bank.freeserve.co.uk> wrote in message
news:c7**********@news6.svr.pol.co.uk...

"William L. Bahn" <wi*****@toomuchspam.net> wrote in message
I recently challenged one of my students to figure out a way to
determine if fgets() actually received the entire contents of the input
string.
Could someone provide the topic number that deals with trapping
this occurance (if one exists)?

We had a huge row about this a few years ago and the FAQ maintainer still
hasn't come round to admitting that I was right.


Right about WHAT?!?! That it is there? That it isn't there? That is should
be there? That it shouldn't be there? That it should be linked to the one I
mentioned? That it shouldn't be linked to the one I mentioned? You seem to
think that everyone is a mind reader and should immediately know what you
are thinking about when you respond with vague references. That you had a
huge row about "this" a few years ago tells me absolutely nothing of value.
It only gives the appearance that you are making vague claims so that it is
impossible for anyone to refute the claim that you were right about whatever
it was the alleged huge row a few years ago was about.
Nov 14 '05 #3
"William L. Bahn" <wi*****@toomuchspam.net> wrote in message news:<10*************@corp.supernews.com>...
I recently challenged one of my students to figure out a way to determine if
fgets() actually received the entire contents of the input string. When he
was having trouble figuring it out even after I recommended he look
carefully at the difference between the two cases when the input was short
enough and when the input was too long, I suggested he look at the FAQ for
this newsgroup. He came back and said he couldn't find anything, so I went
and looked and, although I thought I remembered seeing it there before, I
couldn't find anything either.
I would have thought it more appropriate to search the func specs for
fgets(). The FAQ isn't a tutorial.
Could someone provide the topic number that deals with trapping this
occurance (if one exists)?

I found 12.20 ( http://www.eskimo.com/~scs/C-faq/q12.20.html ) right away
and this seems a natural spot to place a link to the topic that actually
goes into this issue at length.

Is there a version of the FAQ someplace that is searchable?


I often just browse and search the last posting to clc via google...

http://groups.google.com/groups?selm...1%40eskimo.com

--
Peter
Nov 14 '05 #4
Peter Nilsson wrote:
"William L. Bahn" <wi*****@toomuchspam.net> wrote in message
I recently challenged one of my students to figure out a way to
determine if fgets() actually received the entire contents of
the input string. When he was having trouble figuring it out
even after I recommended he look carefully at the difference
between the two cases when the input was short enough and when
the input was too long, I suggested he look at the FAQ for this
newsgroup. He came back and said he couldn't find anything, so
I went and looked and, although I thought I remembered seeing
it there before, I couldn't find anything either.


I would have thought it more appropriate to search the func
specs for fgets(). The FAQ isn't a tutorial.


I agree. The OP should make a copy of N869.txt available for all
his students. This is almost the ultimate reference.

It is simplest to avoid the testing for conditions etc. by using
ggets. This has the simplicity of gets, without the
insecurities. Available at:

<http://cbfalconer.home.att.net/download/ggets.zip>
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Nov 14 '05 #5

"William L. Bahn" <wi*****@toomuchspam.net> wrote in message

Right about WHAT?!?!


Here's the FAQ's replacement of gets() with fgets().

#include <stdio.h>
#include <string.h>

char answer[100], *p;
printf("Type something:\n");
fgets(answer, sizeof answer, stdin);
if((p = strchr(answer, '\n')) != NULL)
*p = '\0';
printf("You typed \"%s\"\n", answer);

Obviously this is bugged. Less obviously, it is actually worse than using
gets(), because wrong behaviour isn't necessarily superior to undefined
behaviour. (The argument about which is worse is a bit pointless, since the
solution is to use correct behaviour, but it led to a huge row and as a
result the FAQ has not been debugged.)
Nov 14 '05 #6
On Mon, 3 May 2004 18:28:10 +0100,
Malcolm <ma*****@55bank.freeserve.co.uk> wrote:


"William L. Bahn" <wi*****@toomuchspam.net> wrote in message

Right about WHAT?!?!


Here's the FAQ's replacement of gets() with fgets().

#include <stdio.h>
#include <string.h>

char answer[100], *p;
printf("Type something:\n");
fgets(answer, sizeof answer, stdin);
if((p = strchr(answer, '\n')) != NULL)
*p = '\0';
printf("You typed \"%s\"\n", answer);

Obviously this is bugged. Less obviously, it is actually worse than using
gets(), because wrong behaviour isn't necessarily superior to undefined
behaviour. (The argument about which is worse is a bit pointless, since the
solution is to use correct behaviour, but it led to a huge row and as a
result the FAQ has not been debugged.)

I think that each program must decide what should happen when reading a
partial line with fgets. In some circumstances it is quite appropriate
to silently truncate the line on input. In other situations it should be
treated as a serius error in the input data. As it stands an oversized
input line will silently be cut into two or more chunks each of which
looks like a separate line to the program. Depending on circumstances
that can be fatal or benign. A line overflow with gets will hardly
ever be a benign problem, and, what is worse, it isn't detected easily.
If the '\n' character is missing from the read line the line is either
truncated or you hit end of file before the newline at the end of the
last line.

Villy
Nov 14 '05 #7
On Sun, 2 May 2004 03:33:29 -0600, "William L. Bahn"
<wi*****@toomuchspam.net> wrote:
I recently challenged one of my students to figure out a way to determine if
fgets() actually received the entire contents of the input string. <snip>
(you mean line)
<snip> I suggested he look at the FAQ [site] <snip>
Your substantive question has mostly been answered; the if in 7.1
hints at the issue but doesn't really explain it.
Is there a version of the FAQ someplace that is searchable? <snip>


The plaintext version is posted periodically -- monthly IIRC, although
worldnet has abysmal retention on comp.answers so it disappears -- and
available from http://www.eskimo.com/~scs/C-faq/versions.html
as well as the usual repositories for (all?) big-8 FAQs:
http://www.faqs.org/faqs/C-faq/ (lightly HTMLized)
ftp://rtfm.mit.edu/pub/usenet/comp.lang.c/

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #8

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

Similar topics

3
by: Victor | last post by:
I'm trying to run this java program, but somehow the program always quit w/o giving any error msg at all. it happenned inside the first case statements. Strangely, after printing happen2, it just...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
4
by: interpim | last post by:
ok the function is supposed to accept only non-negative integers... but it still accepts letters input through the function. Such as '23e' still passes through. I tried to use isalpha in the or...
26
by: Peter Mount | last post by:
Hello What's the syntax for using fgets() to store a string in memory? I understand that fgets() can solve the problem of storing a string that has more characters than the size of the declared...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
20
by: TTroy | last post by:
Hello, I have found some peculiar behaviour in the fgets runtime library function for my compiler/OS/platform (Dev C++/XP/P4) - making a C console program (which runs in a CMD.exe shell). The...
1
by: Aomighty | last post by:
Hi, I've been creating a simple calculator program that asks whether you want to add, subtract, multiply or divide, asks you for input, and then performs the calculation. Things seem to be going...
285
by: Sheth Raxit | last post by:
Machine 1 : bash-3.00$ uname -a SunOS <hostname5.10 Generic_118822-30 sun4u sparc SUNW,Sun-Fire-280R bash-3.00$ gcc -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/...
2
by: jou00jou | last post by:
Hi, I have trouble using sscanf and fgets to check for overflow. I will post the assignment specification so I could help whoever would kindly like to offer his/her help. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.