{
First I created a new file,cause yours is not proper to me,sorry
And I write 5 members into it,and then read them into an array and
last short them
by the way,there are lot of shorting algorithm,I show you one of them
simple sample:
(*pascal but it is working on delphi 7 too*)
program algorithm;
const n = 6;
var i,j,k,a:integer;
b:array[1..n]of integer;
begin
b[1]:=5;
b[2]:=9;
b[3]:=2;
b[4]:=3;
b[5]:=7;
b[6]:=1;
for i:=1 to n-1 do begin
for j:= i+1 to n do begin
if (b[i]>b[j]) then begin
a:=b[i];
b[i]:=b[j];
b[j]:=a;
end;
end;
end;
(*result*)
for k:=1 to n do begin
writeln(b[k]);
end;
readln;
end.
}
(*This is an example for your question,created in delphi 7*)
program arrange_array;
{$APPTYPE CONSOLE}
uses
SysUtils;
type tr = record
f:string[20];
l:string[20];
end;
var temp:tr; {this will store one record temporary}
allin,allout:array[1..5]of tr;{every elements is one record}
i,j,k,p,x:integer;{these are loop vars}
myfile:file of tr; {need a file var too}
myfilepath:string;{stores the file's path}
begin
{let's fill the array with some old stars,when i was young...}
allout[1].f:='turbo';{first name}
allout[1].l:='b';{last name}
allout[2].f:='mc';
allout[2].l:='hammer';
allout[3].f:='joey b';
allout[3].l:='elis';
allout[4].f:='bg the price';
allout[4].l:='of rap';
allout[5].f:='naughty by';
allout[5].l:='nature';
{let's add the file path and its name and its extension}
myfilepath:='C:\names.dat';
{assign the file to the file var}
assignfile(myfile,myfilepath);
{create it,if it is exists then delete its contents...}
rewrite(myfile);
writeln('Unshorted array: ');
{let's write the above array to this file}
reset(myfile);
for i:=1 to 5 do begin
write(myfile,allout[i]);
writeln(i,'. ',allout[i].f,' ',allout[i].l);
end;
{closing...}
close(myfile);
{open again,now to read into an array}
{$I-}
reset(myfile);
{$I+}
if (ioresult <> 0) then begin
writeln('Error: ',ioresult); {write the error code,just a number...}
readln;
exit;
end;
{read into allin}
j:=1;
while not eof(myfile)do begin
read(myfile,allin[j]);
inc(j,1);
end;
close(myfile);
writeln;
writeln;
{short them,by first name}
for k:=1 to 4 do begin
for p:=k+1 to 5 do begin
if ( allin[k].f > allin[p].f ) then begin
temp:=allin[k];
allin[k]:=allin[p];
allin[p]:=temp;
end;
end;
end;
{write out the results...}
writeln('Shorted array: ');
for x:=1 to 5 do begin
writeln(x,'. ',allin[x].f,' ',allin[x].l);
end;
readln;
end.
{by FlamingClaw 2009.09.}