473,569 Members | 2,489 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

which functions set the end-of-file indicator?

Hi everybody, in a french C book, the author says that only {fgetc,
getc, getchar, fgetwc, getwc, getwchar, fgets, gets, fgetws, getws,
fputc, putc, putchar, fputwc, putwc, putwchar, fputs, puts, fputws}
are guaranteed to set the end-of-file indicator when the end-of-file
is reached, but in C99 standard, I find p 288 (ISO/IEC 9899:TC3
Committee Draft — Septermber 7, 2007 WG14/N1256)

/* =============== ============== */
#include <stdio.h>
/* ... */
int count; float quant; char units[21], item[21];
do {
count = fscanf(stdin, "%f%20s of %20s", &quant, units, item);
fscanf(stdin,"% *[^\n]");
} while (!feof(stdin) && !ferror(stdin)) ;
/* =============== ============== */
It seems to say that fscanf family function set end-of-file indicator
too? which functions set the end-of-file indicator?
Aug 4 '08
80 6419
ni************@ gmail.com wrote:
On 4 août, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
>nicolas.sit... @gmail.com wrote:
OK OK, everybody seems to be ok to say that all I/O functions can
potentially set/clear the end-of-file indicator, but nobody give me
normative reference, and the author says that nothing in the C99
says that all I/O functions can set/clear end-of-file indicator!!!


The normative reference is section 7.19 of the Standard.
I looked at this section, but I didn't find anything saying clearly
that all IO input functions set/clear the end-of-file indicator!
Hasn't it been made clear to you by now that only one poster has said
that all functions that perform an I/O operation set these flags, and
that he was overstating his case, as has been explained more than once?

Aug 4 '08 #11
On 4 août, 21:59, santosh <santosh....@gm ail.comwrote:
nicolas.sit...@ gmail.com wrote:
On 4 août, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
nicolas.sit...@ gmail.com wrote:
OK OK, everybody seems to be ok to say that all I/O functions can
potentially set/clear the end-of-file indicator, but nobody give me
normative reference, and the author says that nothing in the C99
says that all I/O functions can set/clear end-of-file indicator!!!
The normative reference is section 7.19 of the Standard.
I looked at this section, but I didn't find anything saying clearly
that all IO INPUT functions set/clear the end-of-file indicator!

Hasn't it been made clear to you by now that only one poster has said
that all functions that perform an I/O operation set these flags, and
that he was overstating his case, as has been explained more than once?
read what I said : all IO INPUT functions
Aug 4 '08 #12
ni************@ gmail.com wrote:
On 4 août, 21:59, santosh <santosh....@gm ail.comwrote:
>nicolas.sit... @gmail.com wrote:
On 4 août, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
nicolas.sit... @gmail.com wrote:
OK OK, everybody seems to be ok to say that all I/O functions
can potentially set/clear the end-of-file indicator, but nobody
give me normative reference, and the author says that nothing in
the C99 says that all I/O functions can set/clear end-of-file
indicator!!!
>The normative reference is section 7.19 of the Standard.
I looked at this section, but I didn't find anything saying clearly
that all IO INPUT functions set/clear the end-of-file indicator!

Hasn't it been made clear to you by now that only one poster has said
that all functions that perform an I/O operation set these flags, and
that he was overstating his case, as has been explained more than
once?

read what I said : all IO INPUT functions
You have already been told that all input in C is done as if it is
composed of one or more calls to fgetc, and fgetc can most certainly
set the end-of-file indicator, and it's implied that other input
functions modelled on top of it, must also do so. Indeed they have no
choice but to do so. However they do have different methods of
notifying the user of such an exception. For example fgets returns a
null pointer, fread returns a short item count, scanf returns EOF etc.
In all cases you can always determine whether a particular FILE stream
is at end-of-file by calling the feof function, and whether an I/O
error has occurred during the last access by using the ferror function.

Aug 4 '08 #13
santosh wrote:
Eric Sosman wrote:
>ni************@ gmail.com wrote:
>>OK OK, everybody seems to be ok to say that all I/O functions can
potentially set/clear the end-of-file indicator, but nobody give me
normative reference, and the author says that nothing in the C99 says
that all I/O functions can set/clear end-of-file indicator!!!
Unless the post hasn't reached my news server yet, nobody has
claimed that all I/O functions can set or clear the end-of-file
indicator. putc(), for example, cannot. Nor can ftell(), nor
setvbuf(), nor feof(), nor a bunch of others.

To quote vippstar:

All functions that perform IO operations. (ie even perror() can set
the 'error' indicator for stderr if an error occurs at writing)
The O.P. asked about the end-of-file indicator. The end-of-file
indicator and the error indicator are separate indicators, and are
set and cleared under different circumstances.

--
Er*********@sun .com
Aug 4 '08 #14
nicolas.sit...@ gmail.com wrote:
On 4 ao�t, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
...
� � �The normative reference is section 7.19 ofthe Standard.

--
Eric.Sos...@sun .com
I looked at this section, but I didn't find anything saying clearly
that all IO input functions set/clear the end-of-file indicator!
It doesn't explain it in those terms. You have to follow several
intermediate steps.

7.19.7.1p3 says that fgetc() sets the end-of-file indicator.
7.24.3.1p3 says the same for fgetwc(). All wide character input
functions have their behavior defined in terms of successive calls to
fgetwc(), and all byte input functions have their behavior defined in
terms of repeated calls to fgetc() (7.19.3p11). All of the input
functions are defined as either wide character input functions or byte
input functions (7.19.1p3) . Those functions don't have to actually
call fgetc()/fgetwc(), but must produce the same behavior as if they
called fgetc()/fgetwc(), which means that they must set the end-of-
file indicator, when appropriate.
Aug 4 '08 #15
On 4 août, 22:14, santosh <santosh....@gm ail.comwrote:
nicolas.sit...@ gmail.com wrote:
On 4 août, 21:59, santosh <santosh....@gm ail.comwrote:
nicolas.sit...@ gmail.com wrote:
On 4 août, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
nicolas.sit...@ gmail.com wrote:
OK OK, everybody seems to be ok to say that all I/O functions
can potentially set/clear the end-of-file indicator, but nobody
give me normative reference, and the author says that nothing in
the C99 says that all I/O functions can set/clear end-of-file
indicator!!!
The normative reference is section 7.19 of the Standard.
I looked at this section, but I didn't find anything saying clearly
that all IO INPUT functions set/clear the end-of-file indicator!
Hasn't it been made clear to you by now that only one poster has said
that all functions that perform an I/O operation set these flags, and
that he was overstating his case, as has been explained more than
once?
read what I said : all IO INPUT functions

You have already been told that all input in C is done as if it is
composed of one or more calls to fgetc, and fgetc can most certainly
set the end-of-file indicator, and it's implied that other input
functions modelled on top of it, must also do so. Indeed they have no
choice but to do so. However they do have different methods of
notifying the user of such an exception. For example fgets returns a
null pointer, fread returns a short item count, scanf returns EOF etc.
In all cases you can always determine whether a particular FILE stream
is at end-of-file by calling the feof function, and whether an I/O
error has occurred during the last access by using the ferror function.
sorry but, one more time, you don't answer me : can you say precisely,
where in the normative reference it is write that all IO INPUT
functions clear/set the end-of-file indicator cause if I write to the
author without any proof...
Aug 4 '08 #16
Eric Sosman wrote:
santosh wrote:
>Eric Sosman wrote:
>>ni************@ gmail.com wrote:
OK OK, everybody seems to be ok to say that all I/O functions can
potentiall y set/clear the end-of-file indicator, but nobody give me
normative reference, and the author says that nothing in the C99
says that all I/O functions can set/clear end-of-file indicator!!!
Unless the post hasn't reached my news server yet, nobody has
claimed that all I/O functions can set or clear the end-of-file
indicator. putc(), for example, cannot. Nor can ftell(), nor
setvbuf(), nor feof(), nor a bunch of others.

To quote vippstar:

All functions that perform IO operations. (ie even perror() can set
the 'error' indicator for stderr if an error occurs at writing)

The O.P. asked about the end-of-file indicator. The end-of-file
indicator and the error indicator are separate indicators, and are
set and cleared under different circumstances.
You're right. Apologies to vippstar for misquoting him.

Aug 4 '08 #17
ni************@ gmail.com wrote:
On 4 août, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
>nicolas.sit... @gmail.com wrote:
>>OK OK, everybody seems to be ok to say that all I/O functions can
potentially set/clear the end-of-file indicator, but nobody give me
normative reference, and the author says that nothing in the C99 says
that all I/O functions can set/clear end-of-file indicator!!!

The normative reference is section 7.19 of the Standard.
I looked at this section, but I didn't find anything saying clearly
that all IO input functions set/clear the end-of-file indicator!
It's in the same paragraph that says the Moon is made of
green cheese. In other words, the Standard says no such thing:
You are searching for the normative text of a falsehood.

Is it possible that you have confused the end-of-file
indicator with the error indicator? They are not the same.

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

Aug 4 '08 #18
On 4 août, 22:28, Eric Sosman <Eric.Sos...@su n.comwrote:
* * *Is it possible that you have confused the end-of-file
indicator with the error indicator? *They are not the same.

--
Eric.Sos...@sun .com
In fact, the author says that except the functions I mentioned above,
all other are not guaranteed to set the end-of-file OR error
indicator, and he says that other functions are not portable if used
in this way. For french programmers who want to verify my saying, the
book is "méthodolog ie de la programmation en C, norme C99, API POSIX"
de Achille Braquelaire.
Aug 4 '08 #19
Eric Sosman wrote:
ni************@ gmail.com wrote:
>On 4 août, 21:30, Eric Sosman <Eric.Sos...@su n.comwrote:
>>nicolas.sit.. .@gmail.com wrote:
OK OK, everybody seems to be ok to say that all I/O functions can
potentiall y set/clear the end-of-file indicator, but nobody give me
normative reference, and the author says that nothing in the C99 says
that all I/O functions can set/clear end-of-file indicator!!!

The normative reference is section 7.19 of the Standard.
I looked at this section, but I didn't find anything saying clearly
that all IO input functions set/clear the end-of-file indicator!

It's in the same paragraph that says the Moon is made of
green cheese. In other words, the Standard says no such thing:
You are searching for the normative text of a falsehood.

Is it possible that you have confused the end-of-file
indicator with the error indicator? They are not the same.
Pardon me; I overlooked the insertion of the word "input" in
your restatement of the question. Yes, the Standard says that all
input functions can set the end-of-file indicator, but it says so
in the descriptions of the individual functions, not as a blanket
statement about all input functions. (Indeed, the Standard never
defines "input functions" as such, although it does define some
close relatives.)

If we take the commonsense view that "input functions" are the
"wide character input functions" (7.19.1p5) plus fgetc, fgets, fread,
fscanf, getc, getchar, gets, scanf, vfscanf, and vscanf, I believe
that the description of each says it can set the end-of-file
indicator. (I haven't checked, but you're welcome to -- and
maybe to file a Defect Report if any of them forgets to!) You can
also search the function descriptions for those that clear or can
clear the end-of-file indicator; it would be somewhat clumsier to
make a blanket statement about the latter category.

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

Aug 4 '08 #20

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

Similar topics

22
3782
by: TC | last post by:
I have an Access database application with a lot of custom row functions written in VBA. In other words, a lot of queries contain calculated fields which use functions defined in the modules. I am now thinking about upgrading the database from Access to SQL Server. If I do, how can I implement the custom row functions? Is Visual Basic...
11
1484
by: sotto | last post by:
If i have this Interface: Public Interface MyInterface Function test() As Boolean Function test(ByVal MyVar As String) As Boolean End Interface And then i make a Public Class MyOwnClass
1
1430
by: George | last post by:
I am new to VB, I need 2 string functions to return last char and remove last char. I made them up. Am I recreating the wheel? do similar functions exist in String? I could not find them Public Class StringCode Public Shared Function LastStringChar(ByVal str As String) As Char
11
5099
by: Bruce A. Julseth | last post by:
I have: If (Microsoft.VisualBasic.Left(TextBox1.Text, 1) = "$") Then TextBox1.Text = Microsoft.VisualBasic.Right(TextBox1.Text, TextBox1.Text.Length - 1) End If Adding: Imports Microsoft.VisualBasic
5
253
by: Nathan | last post by:
Hi, How can I create a function that will accept as a parameter either a datarow or a datarow array? I want to do this without creating two different functions. Thanks, Nathan
7
2025
by: msxkim | last post by:
How to execute functions in the parent class first and then functions in the child class? For example, I have a parent class with functions 'ONE' and 'TWO' and child class has a function 'THREE'. How should I declare classes so that all three functions are executed when child class is called? Class Parent public function ONE 'code end...
0
3435
by: Zlatko Matiæ | last post by:
Hello. While I was working with Access Projects (Access front-end with MSDE) I was able to call stored procedures by using ADO command and parameters object. Now I am trying to migrate my database from MSDE to Postgre and I'm wondering about stored procedures on Postgre...I couldn't find such expression in Pg documentation, so I suppose...
4
1769
by: markaelkins | last post by:
In the code below I’m trying to figure out how to dynamically perform math functions in a form. To start, I would like to subtract TxtITotal.Text from TxtPTotal.Text and display the results in TxtProLoss.Text before sending the data to the database. I have no idea where to begin. Any help would be greatly appreciated, Thank you,
1
2000
by: Newbie | last post by:
I need the following functions using the standards for Week Numbering IE Week one is the first week with a thursday in it. getWeekStartDate( WeekNum as Integer , YearNumber as Integer ) as Date getWeekEndDate ( WeekNum as Integer , YearNumber as Integer ) as Date getWeekNumber ( dateToCheck as Date ) as Integer numWeeksInYear( year...
31
10290
by: Spiro Trikaliotis | last post by:
Hello, I have a question regarding subtracting a pointer from another one. Assume I have two pointers p1 and p2, which both point to a memory area obtained with malloc(). Assume p1 = p2 + some value c. Now, I want to obtain the difference between the two, that is, the value c. Which type must I use for c? I searched around and did not...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7678
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5222
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3656
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.