Xref: utzoo comp.lang.pascal:1367 comp.sys.mac.programmer:3630 Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!psuvax1!psuvm.bitnet!axs101 From: AXS101@PSUVM.BITNET (Adrian Sullivan) Newsgroups: comp.lang.pascal,comp.sys.mac.programmer Subject: help with a pascal program plz Message-ID: <66066AXS101@PSUVM> Date: 25 Dec 88 16:38:39 GMT Organization: Penn State University - Center for Academic Computing Lines: 369 ok, i REALLY stink at pascal, and for a few days now have been reading these damn pascal books only to find it's confusing me more and more every time i go thru it. i was hopin someone on here would be able to help me... i'm sure just about anyone who knows something about pascal can help, what i'm tryin to do is sort a file... well, here's what the file looks like that needs to be sorted. FIRSTNAME LASTNAME STREET ADDRESS CITY STATE ZIPCODE AREA CODE OF PHONE NUMBER FIRST THREE DIGITS OF PHONE NUMBER LAST FOUR DIGITS OF PHONE NUMBER unneeded text unneeded text and then it repeats and repeats. oh, just to let you know, i'm working with turbo pascal on the mac. the pascal file is as follows.... program testing; type string64= string[64]; var infile, outfile : TEXT; inname, outname : string64; done : boolean; a : integer; i : integer; firstname : string[60]; lastname : string[60]; streetaddr : string[60]; city : string[60]; state : string[60]; zip : integer; firstthree : integer; lastfour : integer; areacode : integer; userid : string[80]; blank : string[60]; { ********************************************************************** } { ********************************************************************** } function verified (message :string64) : boolean; {true if y typed, else false} var ch :char; begin write( message, '? (y/n) '); readln( ch ); verified := ( ch = 'Y' ) or ( ch = 'y' ) end; {verified} { ********************************************************************** } { ********************************************************************** } function duplicated( name : string64 ) : boolean; {true if disk file already exists or permission granted to erase} var tempfile : text; begin if pos( ':', name ) = length ( name ) then duplicated := false {not a disk file if it ends with : } else begin reset( tempfile, name ); if ioresult <> 0 then duplicated := false {file not found} else begin duplicated := not verified( concat( 'remove old ',name ) ); close ( tempfile ) end {else} end {else} end; {duplicated} { ********************************************************************** } { ********************************************************************** } function filesopened (var done :boolean ) : boolean; {return true if input and output files opened} {set done to true if no input file name was entered} var okflag : boolean; begin okflag := false; {assume the worst case} write( 'input file? '); readln(inname); done := length(inname) = 0; if not done then begin reset (infile, inname); if ioresult = 0 then begin write('output file? '); readln(outname); if length(outname) > 0 then if not duplicated (outname) then begin rewrite(outfile, outname); okflag := (ioresult = 0); end; {if} if not okflag then close (infile) end end; filesopened := okflag end; {files opened} { ********************************************************************** } { ********************************************************************** } procedure numberlines; const bs= #8; {backspace control char} begin a:=0; begin while not eof (infile ) do begin a := a +1; readln( infile, firstname); readln( infile, lastname); readln( infile, streetaddr); readln( infile, city); readln( infile, state); readln( infile, zip); readln( infile, areacode); readln( infile, firstthree); readln( infile, lastfour); readln( infile, userid); readln( infile, blank); end; {while} end; end; {numberlines} { ********************************************************************** } { ********************************************************************** } procedure writeit; const bs= #8; {backspace control char} begin i:=1; begin for i := 1 to a do begin write( outfile, firstname); write( outfile, ' '); writeln(outfile, lastname); writeln(outfile, streetaddr); write( outfile, city); write( outfile, ', '); write( outfile, state); write( outfile, ' '); writeln(outfile, zip); write( outfile, '('); write( outfile, areacode); write( outfile, ') '); write( outfile, firstthree); write( outfile, '-'); writeln(outfile, lastfour); end; end; end; {numberlines} { ********************************************************************** } { ********************************************************************** } procedure display; begin writeln; writeln; writeln; writeln; writeln; writeln; writeln; writeln( ' enter the input file volume:name,'); writeln( ' then the output file volume:name,'); writeln( ' or press return to quit.'); end; {display} { ********************************************************************** } { ********************************************************************** } procedure firstnamesort; begin writeln('first name sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure lastnamesort; begin writeln('last name sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure citysort; begin writeln('city sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure statesort; begin writeln('state sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure zipsort; begin writeln('zipcode sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure areacodesort; begin writeln('area code sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure firstthreesort; begin writeln('first three sort done'); end; { ********************************************************************** } { ********************************************************************** } procedure whatsort; var sortkind : char; sortenter : boolean; begin sortenter:= false; begin while sortenter= false do begin writeln; writeln; writeln( ' please pick a sort type: '); writeln( ' 1: firstname'); writeln( ' 2: lastname'); writeln( ' 3: city'); writeln( ' 4: state'); writeln( ' 5: zipcode'); writeln( ' 6: area code of phone number'); writeln( ' 7: first three digits of phone'); write ( ' your choice: '); readln (sortkind); if sortkind = '1' then begin sortenter:= true; firstnamesort; end; if sortkind = '2' then begin sortenter:= true; lastnamesort; end; if sortkind = '3' then begin sortenter:= true; citysort; end; if sortkind = '4' then begin sortenter:= true; statesort; end; if sortkind = '5' then begin sortenter:= true; zipsort; end; if sortkind = '6' then begin sortenter:= true; areacodesort; end; if sortkind = '7' then begin sortenter:= true; firstthreesort; end; end; end; end; { ********************************************************************** } { ********************************************************************** } begin display; repeat writeln; if filesopened (done ) then begin numberlines; whatsort; writeit; close (infile ); close (outfile); end else if not done then writeln('ERROR : bad or duplicate file name.'); until done end. {end it all} ok. now i can have it read in the file perfectly, and i can have it output the data, but what i need to do inbetween there is sort it. either by first/lastname, city, state, zip, area code, or the first three digits of the phone number. if anyone could help me out, it would be a great help. possibly just stick in a piece of code in one of the sort sections and i could take a look and try to figure out the other ones. please..... anyone.... HELP! Adrian Sullivan AXS101@psuvm.bitnet please e-mail me, thanks in advance for any help