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 Path: g2news2.google.com!news3.google.com!feeder.news-service.com!ecngs!feeder.ecngs.de!130.59.10.21.MISMATCH!kanaga.switch.ch!switch.ch!news.rediris.es!not-for-mail From: m.collado@domain.invalid Newsgroups: comp.lang.ada Subject: Re: C getchar() functionality in Ada Date: Tue, 17 Feb 2009 11:37:11 +0100 Organization: RedIRIS Message-ID: References: <4999ce31$0$90266$14726298@news.sunsite.dk> NNTP-Posting-Host: acedia.ls.fi.upm.es Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: heraldo.rediris.es 1234867033 5741 138.100.10.20 (17 Feb 2009 10:37:13 GMT) X-Complaints-To: jesus.heras@rediris.es NNTP-Posting-Date: Tue, 17 Feb 2009 10:37:13 +0000 (UTC) User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) In-Reply-To: <4999ce31$0$90266$14726298@news.sunsite.dk> Xref: g2news2.google.com comp.lang.ada:4639 Date: 2009-02-17T11:37:11+01:00 List-Id: Thomas Locke escribi�: > Hey all, > > I've started redoing all the K&R C examples in Ada, and I've already hit > a wall that I'm not able to get around. > > I have this C program: http://pastebin.com/fbc6bec5 > > It's very simple, but still I fail to mimick it in Ada. > > The C program happily accepts everything I throw at it, and it responds > with the expected values, whereas my Ada version(s) either fail at > linefeeds, throw End_Error exceptions at me, or spits out too many > linefeeds! > > My current Ada code looks like this: http://pastebin.com/f519f7e37 > > This version works with input from keyboard and when I pipe some data > into it like this: $ echo "FooBar" | ito > > It craps out on files ($ cat SomeFile | ito), where it ignores linefeeds > and throws End_Error exceptions at me when the last character in the > file is a linefeed > > I've tried with Get_Immediate, Look_Ahead, Get_Line and a mixture of > Strings, Characters and Unbounded strings. I just can't make it work. The following seems to work: with Ada.Text_IO; use Ada.Text_IO; procedure Ito is C : Character; begin while not End_Of_File loop Get_Immediate (Item => C); Put (Item => C); end loop; end Ito ; > > Any and all advice are more than welcome. > > :o) > /Thomas -- Manuel Collado - http://lml.ls.fi.upm.es/~mcollado