Re: zipcode selection sort in MR&C
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: zipcode selection sort in MR&C         

Group: comp.lang.fortran · Group Profile
Author: Ron Ford
Date: Aug 20, 2008 17:58

On Tue, 19 Aug 2008 21:03:22 -0800, glen herrmannsfeldt posted:
> Ron Ford wrote:
> (snip)
>
>>>>Donald Trump
>>>>100 Trump Plaza
>>>>New York, NY 10080
> (snip)
>
>> The read should read:
>> read (2, '(a/a/a/a2,i8)',end=10) data_array(i)
>
> and then put the state and zip code on the next line.
>
> C has a format specifier that will allow reading up until
> some set of characters appears to end on the comma.
>
> -- glen

Thanks, Glen. I had two errors going at the same time. One was that I
misspelled addresses.txt when I named the actual file (Germans use one d in
address). That was why windows was creating another one. The other was
that the addresses needed to formatted differently, as you indicated.
Output.txt is now:

T. Boone Pickens
350 Swiftboat Lane
Houston,
TX 45536

Ev Bayh
1016 Humdity Bath
Indianapolis,
IN 47250

Cindy McCain
1000 Richie Rich
Scottsdale,
AZ 85250

Diane Feinstein
250 Harvey Milk Circle
San Fransisco,
CA 96580

Tim Pawlenty
500 Olson way
St. Paul,
MN 56674

Donald Trump
100 Trump Plaza
New York,
NY 10080

after sorting

Donald Trump
100 Trump Plaza
New York,
NY 10080

T. Boone Pickens
350 Swiftboat Lane
Houston,
TX 45536

Ev Bayh
1016 Humdity Bath
Indianapolis,
IN 47250

Tim Pawlenty
500 Olson way
St. Paul,
MN 56674

Cindy McCain
1000 Richie Rich
Scottsdale,
AZ 85250

Diane Feinstein
250 Harvey Milk Circle
San Fransisco,
CA 96580
99 0

If zippy is now:

program zippy
use sort
implicit none
integer, parameter :: array_size = 100
type (address), dimension (array_size) :: data_array
integer :: i,n, ios

open(2, file='addresses2.txt', status='old', iostat=ios, err=99)
open(3, file='output.txt', status='replace')
do i = 1, array_size
read (2, '(/a/a/a/a2,i8)',end=10) data_array(i)
write (3, '(/a/a/a/a2,i8)') data_array(i)
end do
10 n = i - 1
call selection_sort (data_array(1:n))

write(3, '(//a)') 'after sorting'
do i = 1, n
write (3, '(/a/a/a/a2,i8)') data_array(i)
end do

99 write(3,*) "99", ios
end program zippy

, is maybe the source of error at the end that it appears to expect 100
entries? How can you tell it to read until there's no more to be read?
--
We are here and it is now. Further than that, all human knowledge is
moonshine. 3
H. L. Mencken
no comments
diggit! del.icio.us! reddit!