From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f7e3d24b1fe22fd X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-11-24 21:14:40 PST Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!europa.netcrusader.net!63.208.208.143!feed2.onemain.com!feed1.onemain.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3A1F4ABC.AB68A5C2@acm.org> From: Jeff Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: End_Of_File does not work as expected... References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sat, 25 Nov 2000 05:14:39 GMT NNTP-Posting-Host: 158.252.122.142 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 975129279 158.252.122.142 (Fri, 24 Nov 2000 21:14:39 PST) NNTP-Posting-Date: Fri, 24 Nov 2000 21:14:39 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: supernews.google.com comp.lang.ada:2409 Date: 2000-11-25T05:14:39+00:00 List-Id: Mika Fischer wrote: > Why does the following code not work as expected? I can't tell you, since I don't know how you expected it to work. It probably works as I expect it to work. > procedure Echo is > > c: Character; > > begin > while not End_Of_File loop > Get(c); > Put(c); > end loop; > end Echo; This code should not compile, since Get and Put are not defined. If I assume that the source file contains with Ada.Text_IO; use Ada.Text_IO; followed by the given code, it would compile. All my following discussion is based on this assumption. > When I compile it and invoke it like in "cat file | ./echo" it throws the > exception END_ERROR which indicates that I tried to read from a file > beyond the end of file. > So why is End_Of_File false when it should be true? Without knowing the exact contents of file, including any line and page terminators, I cannot answer. However, if you carefully read the descriptions of End_Of_File and Get (Character) in ARM A.10, you will see that there are many situations in which End_Of_File is False, yet Get (Character) will attempt to read past the end of the file. This is probably what you are encountering. You can find the ARM at http://www.adapower.com/rm95/index.html > Also if I invoke the program as "./echo" and type for example "ddd" and > press the enter key, the following appears on my screen: > > ---- > ddd > ddd > ---- > > When I press Enter once more its this: > > ---- > ddd > ddd > > ---- > > I also don't understand why it behaves as it does. This is expected. The first line is echoed by your operating system, and the second by your program. The second is echoed by the operating system but not by your program. > As you have certainly noticed I don't really have a clue about Ada. So my > apollogies if this question ist just too stupid :-) (And sorry for my > English...) Text_IO has a number of features that seem counter-intuitive to many people when they first encounter it, especially if they have not read the descriptions of the operations, so your question is not *too* stupid. For example, many people assume that Get_Line always skips a line terminator. For a university course, it is probably better to ask your instructor before posting here. -- Jeff Carter "I blow my nose on you." Monty Python & the Holy Grail