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,d54559bde05f5bb8 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!r15g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Weird string I/O problem Date: Tue, 2 Dec 2008 08:39:41 -0800 (PST) Organization: http://groups.google.com Message-ID: <184a2bfd-4d95-434b-91e0-64c8f869e8b7@r15g2000prh.googlegroups.com> References: <6d9d4120-3af9-42c6-b3e9-768418948084@t3g2000yqa.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1228236000 24989 127.0.0.1 (2 Dec 2008 16:40:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 2 Dec 2008 16:40:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: r15g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2853 Date: 2008-12-02T08:39:41-08:00 List-Id: On Dec 1, 11:53 pm, christoph.gr...@eurocopter.com wrote: > On 2 Dez., 07:55, a...@anon.org (anon) wrote: > > > Have you ever learn, you do not give the complete code, because too many > > students like to steal code for there grade. > > > So, you ONLY give enough code for the person to use the code to > > build his own. And that's what i did! > > anon pretending educational intentions presents wrong code. What a > nice fellow! > > for index in input_string'Range loop > ... Here get the next char from the input stream. > ... Be careful, there might be control characters. > ... See Ada.Text_IO for appropriate subprograms. > exit when char = CR or char = LF ; -- not all OSes treat end of > lines like this > this is why there are > End_of_Line queries > input_string ( index ) := char ; > Last := Index ; > end loop; > > This would be the way, I guess. Also make sure it works when the user enters an empty string. Aside from the error of trying to test characters for CR and LF, and the issue that it wouldn't even work on an OS that returns *both* CR and LF in sequence, when the above code is executed multiple times to input multiple lines, there's a nasty bug (in anon's original code) that will show up when the input is an empty string. In other words, even from an educational standpoint, the original code seems more useful as a "Can you spot all the errors in this?" exercise than as something to help a student get started building his or her own. (And yes, I did catch the missing semicolon after "end loop".) Kind of reminds me of an old MAD Magazine puzzle where they showed you a picture that had everything possible wrong with it (including an upside-down sign that said MAD IS NOT FUNNY), and asked "What's wrong with this picture"? On the answer page, it simply said "Better you should ask, what's RIGHT with this picture"? -- Adam