thieumao

Ghi Sửa File trong Pascal

May 12th, 2013
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.05 KB | None | 0 0
  1. program GhiSua;
  2. uses crt;
  3. type mang=array[1..200] of byte;
  4. var
  5.   F,F2,F3: Text;
  6.   path: string;
  7.   n,m,i,stt,data:byte;
  8.   a,b:mang;
  9.   kt:char;
  10. begin
  11.  
  12.   clrscr;
  13.   write('Nhap path file: ');='mao.txt';
  14.   readln(path);
  15.   {path:='/home/thieumao/Desktop/em.txt';}
  16.   assign(F, path);
  17.   rewrite(F);
  18.   write('Nhap so phan tu: ');
  19.   readln(n);
  20.   writeln(F,n);
  21.   for i:=1 to n do
  22.     begin
  23.       write('a[',i,']= ');
  24.       readln(a[i]);
  25.       write(F,a[i]:3);
  26.     end;
  27.   writeln('***Da ghi file xong!***');
  28.   close(F);
  29.   {*************SUA*FILE***************}
  30.   assign(F2,path);
  31.   reset(F2);
  32.   readln(F2,m);
  33.   for i:=1 to m do read(F2,b[i]);
  34.   repeat
  35.     repeat
  36.       write('Nhap stt muon sua: '); readln(stt);
  37.     until (stt>0) and (stt<=m);
  38.     write('Nhap so muon thay: '); readln(data);
  39.     b[stt]:=data;
  40.     write('Co sua nua khong? <C/K>: '); readln(kt);
  41.   until upcase(kt)='K';
  42.   {for i:=1 to m do write(b[i]:2);}
  43.   close(F2);
  44.   assign(F3,path);
  45.   rewrite(F3);
  46.   writeln(F3,m);
  47.   for i:=1 to m do write(F3,b[i]:3);
  48.   close(F3);
  49. end.
Advertisement
Add Comment
Please, Sign In to add comment