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.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,807c81be80f60569 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: put a character back to the input stream Date: 1999/10/24 Message-ID: <7uuvac$9be$1@nnrp1.deja.com>#1/1 X-Deja-AN: 539911131 References: <3811B324.D0CC49A3@hotmail.com> <7ut91r$nih@drn.newsguy.com> X-Http-Proxy: 1.0 x32.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Sun Oct 24 12:50:19 1999 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-10-24T00:00:00+00:00 List-Id: In article <7ut91r$nih@drn.newsguy.com>, nabbasi@pacble.net.NOSPAM wrote: > package Interfaces.C_Streams has function : > > function ungetc (c : int; stream : FILEs) return int; > > (and all the other standard C stream functions.) Yes, you could use this, but it is hard work (and of course GNAT-specific). You have to use the special functions provided in GNAT to extract the stream identifier from a Text_IO file (these are very useful in such situations, see the GNAT reference manual for details). But really this is entirely the wrong direction, and is a consequence of following an incorrect suggestion of how to solve the original problem. The proper response to the original question is to use Text_IO.Look_Ahead, which is the standard facility provided to solve this problem. In Ada, rather than read the character and unread it (which is a bit of a kludgy concept, and there are typically limitations on how many times unread can be called), the paradigm is to look ahead at the next character without consuming it. This will solve your problem in a perfectly neat way, neater than the corresponding C, since you won't need to remember to do an ungetc. During the design, the veiwpoint was that look ahead was a better way to provide the required underlying functionality for solving problems of exactly this kind than the "unread" approach. Anyway, thanks for describing not only the solution you were seeking (unread) but also the underlying problem (figuring out what to read next). That allows us to give the appropriate response. Robert Dewar Sent via Deja.com http://www.deja.com/ Before you buy.