473,698 Members | 2,571 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 6470
In article <g7**********@p anix3.panix.com >,
Greg Comeau <co****@comeauc omputing.comwro te:
>In article <1217878106.929 229@news1nwk>,
Eric Sosman <Er*********@su n.comwrote:
>>... set ... the end-of-file
indicator. putc(), for example, cannot.

Dunno if we're using different words or not, but
putc certainly can return EOF.
Oops, we're definitely using different words,
so while what I wrote is true, you were clearly talking
about something else.
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Aug 5 '08 #31
co****@panix.co m (Greg Comeau) writes:
In article <1217878106.929 229@news1nwk>,
Eric Sosman <Er*********@su n.comwrote:
>>... set ... the end-of-file
indicator. putc(), for example, cannot.

Dunno if we're using different words or not, but
putc certainly can return EOF.
Certainly.

Returning EOF and setting the end-of-file indicator are two different
things.

Concretely:

before = feof(stdout);
putc_result = putc('x');
after = feof(stdout);

It can be the case that putc_result == EOF, but it cannot be the case
that before==0 and after!=0.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 5 '08 #32
Greg Comeau wrote:
Eric Sosman <Er*********@su n.comwrote:
>... set ... the end-of-file
indicator. putc(), for example, cannot.

Dunno if we're using different words or not, but
putc certainly can return EOF.
Returning EOF signals error, not setting of end-of-file indicator.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Aug 5 '08 #33
On Mon, 4 Aug 2008 18:45:02 -0700 (PDT), vi******@gmail. com wrote:
>On Aug 5, 3:40 am, com...@panix.co m (Greg Comeau) wrote:
>In article <1217878106.929 229@news1nwk>,
Eric Sosman <Eric.Sos...@su n.comwrote:
>... set ... the end-of-file
indicator. putc(), for example, cannot.

Dunno if we're using different words or not, but
putc certainly can return EOF.

The end of file indicator has nothing to do with the EOF macro.
When putc returns EOF, it means one of the following

o error with the stream; ferror() should return non-zero.
o EOF is a valid byte value that has been written to the stream.
The second case cannot be. EOF is guaranteed to be negative. While
it is certainly possible to pass this value to putc, it will be
converted to unsigned char (7.19.7.8-2 and 7.19.7.3-2). It is this
positive value which will be returned, not EOF.
>
Mr Sosman is talking about file streams that feof() returns non-zero
for. (ie the eof flag is set).
putc cannot set that flag.
--
Remove del for email
Aug 5 '08 #34
Barry Schwarz wrote:
On Mon, 4 Aug 2008 18:45:02 -0700 (PDT), vi******@gmail. com wrote:
>>On Aug 5, 3:40 am, com...@panix.co m (Greg Comeau) wrote:
>>In article <1217878106.929 229@news1nwk>,
Eric Sosman <Eric.Sos...@su n.comwrote:

... set ... the end-of-file
indicator. putc(), for example, cannot.

Dunno if we're using different words or not, but
putc certainly can return EOF.

The end of file indicator has nothing to do with the EOF macro.
When putc returns EOF, it means one of the following

o error with the stream; ferror() should return non-zero.
o EOF is a valid byte value that has been written to the stream.

The second case cannot be. EOF is guaranteed to be negative. While
it is certainly possible to pass this value to putc, it will be
converted to unsigned char (7.19.7.8-2 and 7.19.7.3-2). It is this
positive value which will be returned, not EOF.
And here is a test program as well:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
int retval = 0, rc = 0;
puts("Writing EOF to stderr with putc...");
retval = putc(EOF, stderr);
if (retval == EOF) {
printf("\nputc returned EOF. Value is: %d\n", retval);
if (ferror(stderr) ) {
puts("Error indicator for stderr set.");
rc = EXIT_FAILURE;
}
} else printf("\nputc returned: %d\n", retval);
return rc;
}

$ ./a.out
Writing EOF to stderr with putc...
?
putc returned: 255
$

Aug 5 '08 #35
On Aug 5, 11:44 am, Barry Schwarz <schwa...@dqel. comwrote:
On Mon, 4 Aug 2008 18:45:02 -0700 (PDT), vipps...@gmail. com wrote:
<snip>
The end of file indicator has nothing to do with the EOF macro.
When putc returns EOF, it means one of the following
o error with the stream; ferror() should return non-zero.
o EOF is a valid byte value that has been written to the stream.

The second case cannot be. EOF is guaranteed to be negative. While
it is certainly possible to pass this value to putc, it will be
converted to unsigned char (7.19.7.8-2 and 7.19.7.3-2). It is this
positive value which will be returned, not EOF.
No it can be. We had a recent discussion about this and I think
everyone agreed that it's possible for EOF to be a valid byte.

google thread
<http://groups.google.com/group/comp....thread/thread/
9047fe9cc86e1c6 a/d5b9489e0b16a41 5>
or use the message id
<c9************ *************** *******@e39g200 0hsf.googlegrou ps.com>
Aug 5 '08 #36
On Aug 5, 12:35 pm, santosh <santosh....@gm ail.comwrote:
Barry Schwarz wrote:
On Mon, 4 Aug 2008 18:45:02 -0700 (PDT), vipps...@gmail. com wrote:
>On Aug 5, 3:40 am, com...@panix.co m (Greg Comeau) wrote:
In article <1217878106.929 229@news1nwk>,
Eric Sosman <Eric.Sos...@su n.comwrote:
>... set ... the end-of-file
indicator. putc(), for example, cannot.
>Dunno if we're using different words or not, but
putc certainly can return EOF.
>The end of file indicator has nothing to do with the EOF macro.
When putc returns EOF, it means one of the following
o error with the stream; ferror() should return non-zero.
o EOF is a valid byte value that has been written to the stream.
The second case cannot be. EOF is guaranteed to be negative. While
it is certainly possible to pass this value to putc, it will be
converted to unsigned char (7.19.7.8-2 and 7.19.7.3-2). It is this
positive value which will be returned, not EOF.

And here is a test program as well:
<snip>

Test programs like this are meaningless.
It's like claiming that CHAR_BIT is 8 and then writing a test program
to back up the claim...
See my response to Mr Schwarz about EOF and putc.
Aug 5 '08 #37
vi******@gmail. com wrote:
On Aug 5, 11:44 am, Barry Schwarz <schwa...@dqel. comwrote:
>On Mon, 4 Aug 2008 18:45:02 -0700 (PDT), vipps...@gmail. com wrote:
<snip>
>The end of file indicator has nothing to do with the EOF macro.
When putc returns EOF, it means one of the following
o error with the stream; ferror() should return non-zero.
o EOF is a valid byte value that has been written to the stream.

The second case cannot be. EOF is guaranteed to be negative. While
it is certainly possible to pass this value to putc, it will be
converted to unsigned char (7.19.7.8-2 and 7.19.7.3-2). It is this
positive value which will be returned, not EOF.

No it can be. We had a recent discussion about this and I think
everyone agreed that it's possible for EOF to be a valid byte.

google thread
<http://groups.google.com/group/comp....thread/thread/
9047fe9cc86e1c6 a/d5b9489e0b16a41 5>
or use the message id
<c9************ *************** *******@e39g200 0hsf.googlegrou ps.com>
Are you specifically claiming that a call to fputc/putc with EOF as it's
first argument will return EOF if a call to ferror on the stream
immediately after the fputc/putc call returns zero?

Aug 5 '08 #38
vi******@gmail. com wrote:
>
.... snip ...
>
No it can be. We had a recent discussion about this and I think
everyone agreed that it's possible for EOF to be a valid byte.
Since EOF is a negative constant, it is hard to represent in an
unsigned char.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Aug 5 '08 #39
CBFalconer said:
vi******@gmail. com wrote:
>>
... snip ...
>>
No it can be. We had a recent discussion about this and I think
everyone agreed that it's possible for EOF to be a valid byte.

Since EOF is a negative constant, it is hard to represent in an
unsigned char.
It is, however, trivial to convert EOF into an unsigned char.

--
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
Aug 5 '08 #40

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

Similar topics

22
3804
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 integrated with SQL Server just as it is with Access? Or does T-SQL in SQL Server offer the...
11
1492
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
1435
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
5106
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
2034
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 fuction
0
3446
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 that there are no such thing on Postgre. On the other hand, I could see that functions could play such...
4
1772
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
2004
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 as Integer ) as Integer Does anyone know if there are these functions ?
31
10328
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 find a definitive answer (not even in the
0
8610
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7740
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
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
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.