Solved

File window character eating

Posted on 1999-01-18
2
148 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
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
For cloud, the “train has left the station” and in the Microsoft ERP & CRM world, that means the next generation of enterprise software from Microsoft is here: Dynamics 365 is Microsoft’s new integrated business solution that unifies CRM and ERP fun…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now