Solved

File window character eating

Posted on 1999-01-18
2
154 Views
Last Modified: 2011-09-20
I'm trying to get into Pascal and I'm having some trouble understanding the file window.
1/ I want to skip leading non-digits from an input stream and I have the following code

read (c);
while not c in ['0'..'9'] do read (c);

This isn't working, properly, I'm not processing all the characters it seems. I'm not sure how to rewrite that loop using the input window. I think I must need it because I think my read statement is going too far.

2/ I'm trying to use the file window to slip blanks, like so

while input^ <> ' ' do read (c);

This sometimes crashes. What am I doing wrong?
0
Comment
Question by:gumby119
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
davidmwilliams earned 200 total points
ID: 1217502
1/ You're right, your input goes too far because when you stop reading, you've already given c the first digit of the number.  You do need to use the file window as you suspected, like this -

  while not (input^ in ['0' .. '9'] do
    read (c);

2/ I expect your code crashes on empty files, or if the file is padded with blanks - because you will try to read past the end of the file.
  Try this routine -

  Finished := False;
  repeat
    if eof then
      Finished := True
    else if input^ = ' ' then
      read (c)
    else
      Finished := True
  until Finished;

  This is a bit more complicated, but more robust !

  Were these perhaps homework questions?  They actually are examples from a Pascal book called 'Oh, Pascal' !  That takes me back to COMP101 ....
0
 

Author Comment

by:gumby119
ID: 1217503
Great stuff, and so quick too
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft is moving in-place eDiscovery & hold from ECP to EOP console under Content Search in Search and Investigation Options.  In this post, I will be showing you how to export emails to a PST file using the Content Search Options.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question