program search_rand_binary !------------------------------------------------------------------------------ !Program: Random Binary File Search !Author: Chris Harper !Date: 4/8/2008 !------------------------------------------------------------------------------ implicit none integer :: search, a, i, EOF character(1) :: c i = 2 !record 1 is the size of file !open an unformatted direct access file with 4 bytes per record open (unit = 10, file = "randombi.dat", status = "old", form = "unformatted", & access = "direct", recl = 4) print *, "Enter a number to search for:" read *, search do !read record i read (10, rec = i, iostat = EOF) a if (EOF < 0) then !if EOF, exit loop print *, search, " not found!" exit else if (EOF > 0) then !if error, print a message and exit print *, "File read error occured. Error Number: ", EOF exit endif if (a == search) then !print record pos print *, a, " found at pos ", i !continue? print *, "Continue searching? (y, n)" read *, c if (c <> "y") exit end if i = i + 1 end do close (10) end program