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.2 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FREEMAIL_REPLYTO,INVALID_MSGID,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f7e3d24b1fe22fd X-Google-Attributes: gid103376,public From: "Mika Fischer" Subject: Re: End_Of_File does not work as expected... Date: 2000/11/25 Message-ID: #1/1 X-Deja-AN: 697557196 X-No-Productlinks: Yes References: <3A1F4ABC.AB68A5C2@acm.org> X-Trace: fu-berlin.de 975147993 5207989 62.54.34.224 (16 [28816]) User-Agent: Pan/0.9.1 (Unix) Reply-To: mika_fischer@gmx.de Newsgroups: comp.lang.ada Date: 2000-11-25T00:00:00+00:00 List-Id: Hi, Jeff! Thanks for your reply! In article <3A1F4ABC.AB68A5C2@acm.org>, "Jeff Carter" 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. OK, sorry. I tell you how I'd expect it to work. When Get(C) has read past the last Character of the file, End_Of_File should return true and the look shoult be left. >> 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. Oh, sorry again. Of course I'm using this line :-) >> 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. It's the same with every file. > 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 All I can see is this: | function End_Of_File return Boolean; | | (25) | Operates on a file of mode In_File. Returns True if a file | terminator is next, or if the combination of a line, a page, and a | file terminator is next; otherwise returns False. which doesn't explain why that does not work in my program. >> 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. Yeah, well. But if I read one character at once I would expect it to look like this: ---- dddddd ---- Or has this got something to do with buffered output? I'll look this up. >> 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. Well, I don't know how it is in the US, but here we hear the lectures, get our excercises and are supposed to solve them at home. We then bring the solutions back, they are corrected and handed back to us. But sorry if I should have bothered you. Mika.