Board index » delphi » Exceeding the 255 character limit.

Exceeding the 255 character limit.

Quote
jeff menzie wrote:

> I wrote a program which finds the average number of characters per word, and
> average number of words per sentence. My teacher wants me to test it (even
> though I already know it works) with some text he gave us, which is longer
> than 255 characters. How do i get around this. The program is below, written
> in TP 3.0 from 1985.

[ laughing uncontrollably... ]

You know it works but your teacher has already uncovered a bug without
even executing the program. Apparently it doesn't work as well as you
thought it did. Let this be a lesson to all of us!

AME

 

Re:Exceeding the 255 character limit.


I wrote a program which finds the average number of characters per word, and
average number of words per sentence. My teacher wants me to test it (even
though I already know it works) with some text he gave us, which is longer
than 255 characters. How do i get around this. The program is below, written
in TP 3.0 from 1985.

program n8_16 (input,output);
{$B-}
const bl=' ';
      pe='.';

var tx : char ;
    co,wo,se,w1 : integer ;

procedure work (tx : char);
begin
     if (tx <>bl) and(tx <>pe) then co := co + 1;
     if (tx = bl) or (tx = pe) then wo := wo + 1;
end;

procedure sewo (tx : char);
begin
     if (tx = bl) or (tx = pe) then se := se + 1;
     if (tx = pe) then w1 := w1 + 1;
end;

begin
     co := 0;
     writeln ('Enter text to be averaged ');
     writeln;
     while not eoln do
     begin
          read (tx);
          work (tx);
          sewo (tx);
     end;
     writeln ;
     writeln ('average of ',(co/wo):0:2,' characters per word');
     writeln ('average of ',(se/w1):0:2,' words per sentence');
end.

Re:Exceeding the 255 character limit.


On Thu, 30 Jan 1997 01:02:26 GMT,  je...@icu.com (jeff menzie) wrote:

Quote
>I wrote a program which finds the average number of characters per word, and
>average number of words per sentence. My teacher wants me to test it (even
>though I already know it works) with some text he gave us, which is longer
>than 255 characters. How do i get around this. The program is below, written
>in TP 3.0 from 1985.

Barring errors in the original program, you are much closer than you might
imagine.  In fact, you only need add three statements and one compiler
directive.  At the top of your program add compiler directive G128 to allow
redirected input through a 128 byte buffer.  

Your program already handles long lines.  The only problem is, it reads only one
line then terminates.  Nest your "while not eoln" inside a "while NOT(EOF)" to
process a whole file.  Of course you will need to place a "readln" following
your "While not eoln" statement.  This readln will move the file pointer past
the end of line and position at the beginning of the next line.

You might want to extend the prompt by adding something like, "Enter Ctrl+Z when
done.".  I tested the modified program against a fairly large file and
encountered a few problems.  I found that integers weren't large enough to
handle the counts.  If you are afraid of accumulating counts greater than 32767
then you might want to use reals.  Another problem is that you didn't initialize
all your counters.

I didn't spend too much time looking, but I did think of one logic error.  Your
code assumes that words are separated by exactly one space.  If a sentence is
followed by two spaces, your logic bumps the word count, (e.g. counts a zero
length word).  If you want to preserve as much of the code as you can, you might
add one character variable to hold the last character.  Initialize it as a
space, then count words only when the previous character is not a space.  Don't
forget to re-initialize it to a space at the end of each line.

You might also consider reducing the sentence count when the last character was
a period and the current is not a space.  Counting sentences when you encounter
a period will properly handle a sentence followed by EOF, but you need to reduce
the number of sentences when you encounter something like "1.23" or
"command.com".  You can decide if they count as one word or two.  

Depending on the program requirements, you may also need to consider Pascal
style range indicators "1..4", and ellipses "...".  OTH all this may be beyond
scope and need not be coded.  

    ...red

Re:Exceeding the 255 character limit.


Quote
In article <E4sqw3....@nonexistent.com>, jeff menzie <je...@icu.com> wrote:
>I wrote a program which finds the average number of characters per word, and
>average number of words per sentence. My teacher wants me to test it (even
>though I already know it works) with some text he gave us, which is longer
>than 255 characters. How do i get around this. The program is below, written
>in TP 3.0 from 1985.

You must be those who have never seen a type-writer. In those one had to
press a key marked with
                           |
                       <---+

after one had written some 60-70 characters. Maybe you should try that
approach.

Quote

>program n8_16 (input,output);
>{$B-}
>const bl=' ';
>      pe='.';

>var tx : char ;
>    co,wo,se,w1 : integer ;

>procedure work (tx : char);
>begin
>     if (tx <>bl) and(tx <>pe) then co := co + 1;
>     if (tx = bl) or (tx = pe) then wo := wo + 1;
>end;

>procedure sewo (tx : char);
>begin
>     if (tx = bl) or (tx = pe) then se := se + 1;
>     if (tx = pe) then w1 := w1 + 1;
>end;

>begin
>     co := 0;
>     writeln ('Enter text to be averaged ');
>     writeln;
>     while not eoln do
>     begin
>          read (tx);
>          work (tx);
>          sewo (tx);
>     end;
>     writeln ;
>     writeln ('average of ',(co/wo):0:2,' characters per word');
>     writeln ('average of ',(se/w1):0:2,' words per sentence');
>end.

Osmo

Other Threads