Solved

File window character eating

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default value in Delphi component 2 523
Delphi 2007 printer setup problem 8 786
How do you get the IP address of a network? 12 289
Pass a string reference from one unit to another 8 125
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
After-hours service is a fact of life for most MSPs. While not the most pleasant aspect of the job, there are ways to make after-hours servicing a more profitable and organized enterprise.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

680 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