Pascal/Turbo Pascal - Fichero de texto

 
Vista:
sin imagen de perfil

Fichero de texto

Publicado por Pablo (11 intervenciones) el 06/10/2016 00:21:46
Hola ! Tengo una duda ! Quería saber cómo pasar datos de un arreglo de registros a un archivo de texto. Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Fichero de texto

Publicado por ramon (5 intervenciones) el 06/10/2016 17:00:01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{Mira esto}
 
program archivoreg;
   uses
     crt;
   const
      max = 12;
      archireg = 'datosreg.dat';
      architext = 'textoreg.txt';
 
    type
      registro = record
           dninumero       : string[15];
           nombre          : string[70];
           primapellido    : string[70];
           segundoapellido : string[70];
           fechanacimiento : string[12];
         end;
 
       arreglodatos = array[1..max] of registro;
 
 
   var
     datos : arreglodatos;
     f : file of registro;
     t : text;
     cont : integer;
     salir : boolean;
     tecla : char;
 
 
     procedure entradaregistros;
     begin
        cont := 1;
        salir := false;
       repeat
          clrscr;
          writeln('  Entrada De Registro Num. ',cont);
          writeln;
          write('   Entre DNI : ');
          readln(datos[cont].dninumero);
          write('   Entre Nombre : ');
          readln(datos[cont].nombre);
          write('   Entre 1. Apellido : ');
          readln(datos[cont].primapellido);
          write('   Entre 2. Apellido : ');
          readln(datos[cont].segundoapellido);
          write('   Entre Fecha Nacimiento : ');
          readln(datos[cont].fechanacimiento);
          writeln;
          writeln('   Desea Entrar Mas Datos [S/N]');
         repeat
             tecla := upcase(readkey);
         until tecla in['S','N'];
         if tecla = 'S' then
         begin
         cont := cont + 1;
         if cont > max then
         salir := true;
         end
      else
         salir := true;
       until salir = true;
     end;
 
 
 
     procedure guardaregistro;
     var
       h : integer;
       tama : word;
     begin
         assign(f,archireg);
      {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
        rewrite(f);
        for h := 0 to cont  do
        begin
           seek(f,h);
           write(f,datos[h]);
        end;
         close(f);
      end
   else
     begin
        tama := filesize(f) - 1;
        for h := 1 to cont do
        begin
           seek(f,tama + h);
        end;
        close(f);
     end;
    end;
 
    procedure pasaregistroatexto;
    var
      kk : word;
    begin
       assign(f,archireg);
    {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
      writeln('   Error De Archivo O No Existe Pulse Una Tecla');
      readkey;
    end
  else
    begin
       assign(t,architext);
       rewrite(t);
     for kk := 0 to filesize(f) - 1 do
     begin
        seek(f,kk);
        read(f,datos[1]);
        writeln(t,datos[1].dninumero,' ',datos[1].nombre,' ',
        datos[1].primapellido,' ',datos[1].segundoapellido,' ',
        datos[1].fechanacimiento);
     end;
     close(f);
     close(t);
    end;
   end;
 
   procedure mostrartexto;
   var
     line : string;
   begin
      clrscr;
      assign(t,architext);
   {$I-} reset(t); {$I+}
   if ioresult = 0 then
   begin
      while not eof(t) do
      begin
        readln(t,line);
        writeln('   ',line);
      end;
      close(t);
      writeln;
      writeln('   Pulse Una Tecla');
      readkey;
   end
 else
    begin
       writeln('   Error De Archivo O No Existe Pulse Una Tecla');
       readkey;
    end;
  end;
 
 
 
   begin
      entradaregistros;
      guardaregistro;
      pasaregistroatexto;
      mostrartexto;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil

Fichero de texto

Publicado por Pablo (11 intervenciones) el 10/10/2016 07:24:51
Muchas gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar