Pascal/Turbo Pascal - Escribir archivo de acceso directo

 
Vista:
sin imagen de perfil

Escribir archivo de acceso directo

Publicado por Quentin (3 intervenciones) el 04/01/2014 21:41:29
Hola. Bueno, pues perdón si estoy preguntando algo muy obvio o parecido pero, soy muy principiante.

La cuestión es que necesito que, en un archivo de acceso directo, queden grabados varios datos de varias personas.

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
Type
    T_DatosAlumnos  = record
                      Nombreyapellido : string[50];
                      DNI             : integer;
                      Carrera         : string[15];
                      Curso           : string[10];
                      Nota1           : real;
                      Nota2           : real;
                      End;
 
 
Var
   Opcion          : char;
   Matriz          : array[1..25] of T_DatosAlumnos;
   Ultimo          : integer;
   Archivo         : file of T_DatosAlumnos;
 
 
Procedure CargarCurso;
Var
   I : integer;
Begin
Clrscr;
writeln('Se ha dado inicio a la carga de un curso.');
For I:=Ultimo to 1 do
Begin
       While Ultimo < 1 do
       Ultimo:= Ultimo+1;
           writeln();
           writeln('INGRESE:');
           writeln('Nombre y Apellido del alumno:');
           readln(Matriz[Ultimo].Nombreyapellido);
           writeln('DNI del alumno:');
           readln(Matriz[Ultimo].DNI);
           writeln('Carrera del alumno:');
           readln(Matriz[Ultimo].Carrera);
           writeln('Curso del alumno:');
           readln(Matriz[Ultimo].Curso);
           writeln('Nota del alumno en el parcial anual primero:');
           readln(Matriz[Ultimo].Nota1);
           writeln('Nota del alumno en el parcial anual segundo:');
           readln(Matriz[Ultimo].Nota2);
End;
End;


La variable "Archivo" esta asignada a un archivo de texto en disco. Esto lo hice en el cuerpo principal del programa.

¿Qué debo hacer para que los datos de la matriz se graben en el archivo? ¿Basta con abrir el archivo al inicio del procedimiento "CargarCurso" y cerrarlo al final del procedimiento antes citado? Lo he intentado y no me funcionó.

Frente al hecho de que el archivo sea de acceso directo, ¿voy a tener la posibilidad de dirigirme al archivo (.txt) en disco y poder visualizar los datos ingresados durante la ejecución del "programa"?

Desde ya, muchísimas 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
sin imagen de perfil

Escribir archivo de acceso directo

Publicado por Quentin (3 intervenciones) el 06/01/2014 12:48:04
Por favor, alguien que me ayude.
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

Escribir archivo de acceso directo

Publicado por ramon (2158 intervenciones) el 06/01/2014 13:09:55
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{ Como me comentas tienes un archivo de texto para estos datos pero esto tiene que
  ser un archivo de registros que no se manejan como lo de texto porlo tanto espero
  que esto te sirva.
  Aunque tenga extension txt es un archivo de registros normal mente tendria que
  ser con estension diferente por ejemplo dat.}
 
program alumnos;
  uses
    crt;
  Type
     T_DatosAlumnos  = record
                      Nombreyapellido : string[50];
                      DNI             : longint;
                      Carrera         : string[15];
                      Curso           : string[10];
                      Nota1           : real;
                      Nota2           : real;
                      End;
 
 
Var
   Opcion          : char;
   Matriz          : array[1..25] of T_DatosAlumnos;
   Ultimo          : integer;
   Archivo         : file of T_DatosAlumnos;
 
 
 
  procedure guarda_datos_entrados(dat : T_DatosAlumnos);
  begin
     assign(archivo,'alumnos.txt');
  {$I-} reset(archivo); {$I+}
  if ioresult <> 0 then
  begin
     rewrite(archivo);
     seek(archivo,0);
     write(archivo,dat);
     close(archivo);
  end
 else
    begin
       seek(archivo,filesize(archivo));
       write(archivo,dat);
       close(archivo);
    end;
  end;
 
  procedure leer_datos_de_archivo(var cuat : longint);
  var
    i : longint;
  begin
     assign(archivo,'alumnos.txt');
    {$I-} reset(archivo); {$I+}
     if ioresult <> 0 then
     begin
        writeln('Error De Archivo Pulse Una Tecla');
        readkey;
     end
   else
      begin
         if filesize(archivo) - 1 <= 24 then
         begin
            for i := 0 to filesize(archivo) - 1 do
            begin
            seek(archivo,i);
            read(archivo,matriz[i + 1]);
            end;
         end
      else
          begin
             for i := 0 to 24 do
            begin
            seek(archivo,i);
            read(archivo,matriz[i + 1]);
            end;
          end;
          cuat := i + 1;
          close(archivo);
      end;
  end;
 
  Procedure CargarCurso;
  Var
   I : integer;
    Begin
      Clrscr;
       writeln('Se ha dado inicio a la carga de un curso.');
       writeln('INGRESE : ');
       writeln;
       write('Nombre y Apellido del alumno : ');
       readln(Matriz[Ultimo].Nombreyapellido);
       write('DNI del alumno : ');
       readln(Matriz[Ultimo].DNI);
       write('Carrera del alumno : ');
       readln(Matriz[Ultimo].Carrera);
       write('Curso del alumno : ');
       readln(Matriz[Ultimo].Curso);
       write('Nota del alumno en el parcial anual primero : ');
       readln(Matriz[Ultimo].Nota1);
       write('Nota del alumno en el parcial anual segundo : ');
       readln(Matriz[Ultimo].Nota2);
       guarda_datos_entrados(Matriz[Ultimo]);
       Ultimo := Ultimo + 1;
       if Ultimo > 25 then
       Ultimo := 25;
   End;
 
  procedure presentadatos;
  var
    tecla : char;
    z : integer;
    reg : longint;
  begin
     leer_datos_de_archivo(reg);
     z := 1;
   repeat
      clrscr;
      writeln('**** Datos Alumnos ****');
      writeln;
      writeln('  Nombre Y Apellido : ',Matriz[z].Nombreyapellido);
      writeln('  Num. DNI          : ',Matriz[z].DNI);
      writeln('  Carrera           : ',Matriz[z].Carrera);
      writeln('  Curso             : ',Matriz[z].Curso);
      writeln('  Primera Nota      : ',Matriz[z].Nota1:0:2);
      writeln('  Segunda Nota      : ',Matriz[z].Nota2:0:2);
      writeln;
      writeln('   Pulse [',chr(24),chr(25),'] [ESC]=Salir');
      repeat
          tecla := readkey;
      until tecla in[#27,#72,#80];
      if tecla = #72 then
      begin
      z := z - 1;
      if z < 1 then
      z := 1;
      end;
      if tecla = #80 then
      begin
      z := z + 1;
      if z > reg then
      z := reg;
      end;
   until tecla = #27;
  end;
 
  procedure menu;
  var
    sal : boolean;
  begin
     sal := false;
     Ultimo := 1;
   repeat
       clrscr;
       writeln('***** Menu General *****');
       writeln;
       writeln('  E = Entrada Datos');
       writeln('  V = Visualizar Datos');
       writeln('  S = Salir');
       writeln;
       writeln('<<<<< Elija Opcion >>>>>');
       repeat
           Opcion := upcase(readkey);
       until Opcion in['E','V','S'];
       clrscr;
   case Opcion of
 'E' : CargarCurso;
 'V' : presentadatos;
 'S' : sal := true;
    end;
   until sal = true;
  end;
 
 begin
     menu;
 end.
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
sin imagen de perfil

Escribir archivo de acceso directo

Publicado por Quentin (3 intervenciones) el 06/01/2014 20:27:22
Muchas gracias Ramón. Trataré de aprender de tu código, lo analizaré muy lentamente.
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