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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,46ea53533b75e179 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-02-26 22:49:38 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!204.127.198.201.MISMATCH!wn51feed!worldnet.att.net!attbi_s52.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: count_string program References: <403eb73b$1_1@news.tm.net.my> X-Newsreader: Tom's custom newsreader Message-ID: <6MB%b.69233$4o.90172@attbi_s52> NNTP-Posting-Host: 67.161.24.134 X-Complaints-To: abuse@comcast.net X-Trace: attbi_s52 1077864578 67.161.24.134 (Fri, 27 Feb 2004 06:49:38 GMT) NNTP-Posting-Date: Fri, 27 Feb 2004 06:49:38 GMT Organization: Comcast Online Date: Fri, 27 Feb 2004 06:49:38 GMT Xref: archiver1.google.com comp.lang.ada:5884 Date: 2004-02-27T06:49:38+00:00 List-Id: placed the type string is array (positive range <>) of character; to handle a variable number of characters? > Isn't once the user push 'enter' button means their input is done. but > for I in Input'Range loop > Get(Input(I)); > Count := Count + 1; > end loop; That loop does not check the character to see if it is "enter" (probably ascii.cr), so it will continue to loop until Input is full of characters. So if Input had room for, say, 50 characters, the program will demand 50 characters, even if none or all 50 of them are "enter", and then exit the loop. Count will of course be 50. If you actually check the input characters, and exit the loop when you see an "enter", then the count will tell how many were entered. BTW, why are you saving the characters in Input? The rest of the program never does anything with them. You really only need to hold a single input character while you test for "enter". > type String is array (Positive range <>) of Character; Ada automatically has exactly such a String type, so there is no need to duplicate what's already there. > Input : String; A String is an "array of characters". A particular string, like Input, is an array of a certain number of characters. It's like saying a Book is a bunch of pages between two covers. But any specific book has a certain set number of pages. If you want a string of varying length, look up Ada.Strings.Unbounded In the real world, you can probably assume most users won't enter more than, say, 1,000 characters, so you could specify that your program only handles a maximum of 1,000, and then declare Input : String(1 .. 1000);