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-Thread: 103376,8d5bda3619cce0f8 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!news2.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!newsfeeder.ewetel.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 17 Feb 2009 14:01:14 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: C getchar() functionality in Ada References: <4999ce31$0$90266$14726298@news.sunsite.dk> <%5lml.519385$TT4.153916@attbi_s22> <499a6607$0$90276$14726298@news.sunsite.dk> <499a71f2$0$14834$4f793bc4@news.tdc.fi> In-Reply-To: <499a71f2$0$14834$4f793bc4@news.tdc.fi> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <499ab51b$0$30223$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 17 Feb 2009 14:01:15 CET NNTP-Posting-Host: 10c2a5cb.newsspool1.arcor-online.net X-Trace: DXC=Z`k]8@[1\YiJ00P1S40fZgic==]BZ:afn4Fo<]lROoRa^YC2XCjHcbiOC6l0LBaU`o;9OJDO8_SKfNSZ1n^B98ijD=ojT:ZKaRc X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4640 Date: 2009-02-17T14:01:15+01:00 List-Id: Niklas Holsti schrieb: > Thomas Locke wrote: >> Jeffrey R. Carter wrote: >> >>> This is one of the latter cases. You should not be using Character, >>> String, or Ada.Text_IO for this. I suggest you look at streams and >>> Ada.Text_IO.Text_Streams. > > Or Ada.Sequential_IO, instantiated for Character (or Storage_Element, > etc.) which seems to me the best match to the original C program. > However, Sequential_IO has the problem that the standard-input and > standard-output channels are not accessible, you must Open named files. > >> I will try this when my Ada skills have improved a bit. For now I will >> focus on learning how to best use Text_IO. >> >> I wouldn't mind a smallish example on using Ada.Text_IO.Text_Streams >> though... :D > > Here is a copy-input-to-output program with Text_Streams and Character: > > with Ada.Text_IO.Text_Streams; > > procedure Acopy > is > use Ada.Text_IO; > use Ada.Text_IO.Text_Streams; > > Input : constant Stream_Access := Stream (Standard_Input); > Output : constant Stream_Access := Stream (Standard_Output); > > Item : Character; > > begin > > while not End_Of_File (Standard_Input) loop > > Character'Read (Input , Item); > Character'Write(Output, Item); > > end loop; > > end Acopy; We can write the same program in Ada, of course. :-) Only, the Ada version is likely written without resorting to the C's idiomatic "statement-used-as-expression-in-the-loop-conditional". with Interfaces.C; procedure C_1 is use Interfaces.C; function getchar return int; function putchar(item: int) return int; pragma Import(C, getchar); pragma Import(C, putchar); EOF: constant int := -1; -- see c, not_checked: int; begin loop c := getchar; exit when C = EOF; not_checked := putchar(c); end loop; end C_1;