comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Weird string I/O problem
Date: Tue, 2 Dec 2008 08:39:41 -0800 (PST)
Date: 2008-12-02T08:39:41-08:00	[thread overview]
Message-ID: <184a2bfd-4d95-434b-91e0-64c8f869e8b7@r15g2000prh.googlegroups.com> (raw)
In-Reply-To: af997441-7fb0-41bf-80ad-208a95c4bf30@d23g2000yqc.googlegroups.com

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




  reply	other threads:[~2008-12-02 16:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-26  5:52 Weird string I/O problem Jerry
2008-11-26  7:24 ` christoph.grein
2008-11-26  7:38   ` christoph.grein
2008-11-26  8:25     ` Dmitry A. Kazakov
2008-11-26  9:07   ` Jean-Pierre Rosen
2008-11-26 15:21     ` John McCormick
2008-11-26 15:56     ` Adam Beneschan
2008-11-27 10:13       ` Jean-Pierre Rosen
2008-12-01 16:17         ` Adam Beneschan
2008-11-27  4:46 ` Jerry
2008-11-27 10:27   ` Jean-Pierre Rosen
2008-12-01 19:47 ` anon
2008-12-02  5:44   ` christoph.grein
2008-12-02  6:55     ` anon
2008-12-02  7:53       ` christoph.grein
2008-12-02 16:39         ` Adam Beneschan [this message]
2008-12-03  9:16           ` anon
2008-12-03 10:42             ` christoph.grein
2008-12-03 12:21               ` John B. Matthews
2008-12-04  0:15               ` anon
2008-12-04  7:31                 ` christoph.grein
2008-12-04  7:56                   ` Ludovic Brenta
2008-12-04  8:46                     ` Georg Bauhaus
2008-12-03 11:35             ` stefan-lucks
2008-12-04  0:27               ` anon
2008-12-04  8:58                 ` stefan-lucks
2008-12-04 22:54                   ` anon
2008-12-05  9:06                     ` Georg Bauhaus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox