Tassos

First=Last Obj μέσα σε αρχείο (Pascal).

Feb 8th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.61 KB | None | 0 0
  1. {                              Visit:   http://g-lts.no-ip.info/  for more code!              }
  2. program comp;
  3.  
  4. type fint = file of integer;
  5.  
  6. function compare(var f:fint):boolean;
  7.  
  8. // epistrefi false otan to proto antikimeno tou arxiou DEN ine idio me to teleuteo 'H otan to arxio
  9. // den periexi TIPOTA. Epistrefi True otan to proto ine idio me to teleuteo.
  10.  
  11. var arxikoantikimeno,telikoantikimeno:real;
  12. begin
  13.  
  14.     reset(f); // Anigo to arxio gia anagnosi..
  15.  
  16.     if not eof(f) then // An iparxi kati mesa ke den ine adio..
  17.     begin
  18.         arxikoantikimeno := f^; // bale tin proti timi tou file buffer se auti ti metabliti..
  19.     get(f); // pigene stin epomeni 8esi tou arxiou..
  20.  
  21.         while not eof(f) do // oso to arxio den exi teliosi
  22.         begin
  23.             telikoantikimeno := f^; // dine tin timi tou file buffer ( pou se ka8e epanali4i allazi )
  24.                 // se auti tin metabliti. ( opote molis teliosi to arxio i metabliti
  25.                   // auti 8a exi tin teleutea timi tis teleuteas 8esis tou arxiou ).
  26.             get(f);
  27.         end;
  28.  
  29.         compare := arxikoantikimeno = telikoantikimeno; // an to proto ine idio me to teleuteom, tote
  30.                             // episrtefi true sto onoma tis function,
  31.     else                        // allios false ;)
  32.     compare:=false  // diaforetika, an to arxio den exi tpt epestre4e false. ;)
  33.  
  34. end;
  35.  
  36.  
  37. // telos sinartisis isotitas :P
  38. // ==================================================
  39. // diadikasia pou emfanizi ta antikimena tou arxiou
  40.  
  41. procedure readfile(var f:fint);
  42. begin
  43.     reset(f);
  44.     writeln ('Τα αντικείμενα του αρχείου είναι : ');
  45.  
  46.     while not eof(f) do
  47.     begin
  48.         writeln(f^); // gra4e tin timi tou file buffer stin o8oni..
  49.         get(f);
  50.     end;
  51.  
  52. end;
  53.  
  54. // telos diadikasis emfanisis arxion
  55. // =========================================
  56. // Kirios programma!
  57.  
  58.  
  59. var epilogi:integer; f:fint;
  60. begin
  61.     assign(f,'filefalse.txt');
  62.  
  63.     writeln ('Θέλετε να ελέγξετε το αρχείο; ');
  64.     writeln ('1 = Ναι.');
  65.     writeln ('2 = όχι.');readln(epilogi);
  66.  
  67.     if (epilogi = 1) then
  68.     begin
  69.         if compare(f)=true then // dinoume to arxio stin sinartisi ke an epistrefi true  
  70.             writeln ('Το πρώτο με το τελευταίο αντικείμενο είναι ίδια.')
  71.         else
  72.             writeln ('Το πρώτο με το τελευταίο αντικείμενο δεν είναι ίδια.');
  73.     end;
  74.  
  75.     writeln ('Ας δούμε το αρχείο. ');
  76.     readfile(f);
  77.  
  78.  
  79. end.
  80.  
  81. {                              Visit:   http://g-lts.no-ip.info/  for more code!              }
Advertisement
Add Comment
Please, Sign In to add comment