Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
.dat files Posted by KristinK on 2 Dec 2009 at 12:17 PM
I have created a *.dat file and I have to find two of the smallest numbers in the file. I have found one of them, but I can't think of how to find the second one. I've tried some things, they are not working.
Can you help, please? :)
Report
Re: .dat files Posted by Phat Nat on 2 Dec 2009 at 7:29 PM
It all depends on the layout of your .dat file for one.

If you just mean find the two smallest values and there is one number on each line, you could just have two variables (small_1, small_2) and check each line to see if it's smaller.

if your file looks like this:
14
3
7
321
25
5
19


Steps
1) Set small_1 & small_2 to maximum size (65535 for WORD)
2) Check for end of file, if eof, goto 7)
3) Read number (n) from file
4) if n < small_1, set small_1 to n and goto 2)
5) if n < small_2, set small_2 to n and goto 2)
6) goto 2)
7) show small_1 & small_2

That's it.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.