.dat files - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

.dat files

KristinKKristinK Posts: 1Member
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? :)

Comments

  • Phat NatPhat Nat Posts: 757Member
    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:
    [code]
    14
    3
    7
    321
    25
    5
    19
    [/code]

    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.
Sign In or Register to comment.