Solved

File window character eating

Posted on 1999-01-18
2
151 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
how to delete from listbox using edit box 6 301
How to resolve an IP Address to a host name 6 1,696
Delphi TDBX too many connection problem 2 1,165
TZConnection connected in separate thread 2 1,008
Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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