uses CRT;       {Princip: spocita cetnost vyskytu + ....}
type s12=string[12];
var fl1,fl2: file;
    f1,f2: s12;
    PrS,zan: char;
    NumR,NumW,NumWt,DlFl: word; {NRead,NWrite,NWritten}
   buf: array[1..10240] of char; { 10K buffer}

function FileEx(FN:s12):Boolean;
begin
{$I-}Assign(fl1,FN);Reset(fl1);Close(fl1);{$I+}
FileEx:=(IOResult=0) and (FN<>'')
end;

{ tohle je nejake divne; podle vseho to jen zameni znaky, kdyz a>b; zadnou cetnost ani nic to nepocita }
procedure trid;
var stt: char;A,B:byte;
begin
for DlFl:=1 to NumR do begin
 A:=ord(buf[C]);B:=ord([C+1]);
 if A>B then begin stt:=buf[C+1];buf[C+1]:=buf[C];buf[C];:=stt end end
end;

{  tahle cast dela file-read, write + procedura trid}
begin
 f1:=ParamStr(1);
 f2:=ParamStr(2);
if FileEx(f1)=true then
 begin
  WriteLn('Soubor existuje    ... Pracuji');
  Assign(fl2,f2);Rewrite(fl2,1);Assign(fl1,f1);Reset(fl1,1);
  repeat
   BlockRead(Fl1,buf,10240,NumR);
   write('Pretvarim ',NumR,' bytu');
   NumW:=0;

   trid;

   writeln('\Ukladam ',NumW,' bytu');
   BlockWrite(Fl2,buf,NumW,NumWt);
  until NumR<10240;
  Close(fl1);Close(fl2)
 end
else WriteLn('Soubor nenalezen')
end.