?
Solved

File window character eating

Posted on 1999-01-18
2
Medium Priority
?
155 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 800 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

New style of hardware planning for Microsoft Exchange server.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 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