problema de principiante en pascal con archivo (estudiante)
Publicado por Bruno (2 intervenciones) el 27/09/2020 23:59:30
Estaría teniendo problemas en el reglón 173 (esta marcado en el código) es una función que se dedica a verificar que el síntoma ingresado no se repita en el archivo, el problema surge en el momento de realizar "read(sintomas,auxx)" ya que en ese momento el programa se me cierra sin ningún aviso, ya intente diversas cosas (por eso el uso de tantos auxiliares), todo lo referido a provincias y opcion 1 supongo que lo pueden pasar, no creo que suponga algún problema.
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
program tp3(input,output);
uses crt;
type
registro_prov = record
prov: string[30];
codprov: string[30];
end;
registro_sin = record
sin: string;
codsin: string;
end;
var
sintomas: file of registro_sin;
provincias: file of registro_prov;
unaprovincia: registro_prov;
unsintoma:registro_sin;
i,j,opcion: integer;
opcion2: char;
deseo,elec:string;
procedure creaarchi();
begin
{$I-}
if IORESULT = 2 then
begin
rewrite(provincias);
rewrite(sintomas);
// rewrite();
// rewrite();
// rewrite();
end;
{$I+}
end;
procedure asignaGRAL();
begin
assign(provincias,'C:\TP3\provincias.dat');
reset(provincias);
assign(sintomas,'C:\TP3\sintomas.dat');
reset(sintomas);
// assign({archivo,'C:\TP3\enfermedades.dat'});
// reset();
// assign({archivo,'C:\TP3\pacientes.dat'});
// reset();
// assign({archivo,'C:\TP3\historias.dat'});
// reset();
creaarchi();
end;
function control():boolean;
begin
if filesize(provincias) = 0 then
begin
control:= true;
end
else
begin
control:= false;
end;
end;
procedure cargaOP1();
begin
reset(provincias);
if control() then
begin
for i:= 0 to 3 do
begin
writeln('Ingrese el nombre de la provincia');
readln(unaprovincia.prov);
unaprovincia.prov:= upcase(unaprovincia.prov);
writeln('Ingrese el codigo de la provincia');
readln(unaprovincia.codprov);
unaprovincia.codprov:= upcase(unaprovincia.codprov);
write(provincias,unaprovincia);
end;
end;
end;
procedure ordenamientoprovOP1();
var
aux: registro_prov;
begin
reset(provincias);
for i:= 0 to filesize(provincias)-2 do
for j:= i+1 to filesize(provincias)-1 do
begin
seek(provincias,i);
read(provincias,unaprovincia);
seek(provincias,j);
read(provincias,aux);
if unaprovincia.prov > aux.prov then
begin
seek(provincias,i);
write(provincias,aux);
seek(provincias,j);
write(provincias,unaprovincia);
end;
end;
end;
procedure ordenamientocodOP1();
var
aux: registro_prov;
begin
reset(provincias);
for i:= 0 to filesize(provincias)-2 do
for j:= i+1 to filesize(provincias)-1 do
begin
seek(provincias,i);
read(provincias,unaprovincia);
seek(provincias,j);
read(provincias,aux);
if unaprovincia.codprov > aux.codprov then
begin
seek(provincias,i);
write(provincias,aux);
seek(provincias,j);
write(provincias,unaprovincia);
end;
end;
end;
procedure mostrar();
var
a: registro_prov;
begin
reset(provincias);
while not eof(provincias) do
begin
read(provincias,a);
writeln(a.prov);
end;
end;
procedure OPCION_1();
begin
cargaOP1();
ordenamientoprovOP1();
writeln('por prov');
mostrar();
ordenamientocodOP1();
writeln('por cod');
mostrar();
readln();
end;
(*procedure mostrarOP2();
begin
seek(sintomas,0);
while not eof(sintomas) do
begin
read(sintomas,unsintoma);
writeln('sintoma: ', unsintoma.sin);
writeln('codigo: ', unsintoma.codsin);
end;
end;*)
function verifiOP2(sinn:string):boolean;
var
aux: string;
auxx:registro_sin;
begin
reset(sintomas);
repeat
begin
read(sintomas,auxx); (*PRBLEMA PRBLEMA PRBLEMA PRBLEMA *)
aux:=auxx.sin;
if aux = sinn then
begin
writeln('sintomas ya existente');
verifiOP2:= false;
end;
end;
until (aux = sinn) or (eof(sintomas));
if unsintoma.sin <> sinn then
begin
verifiOP2:= true;
end;
end;
function controlOP2():boolean;
begin
if filesize(sintomas) = 0 then
begin
controlOP2:= true;
end
else
begin
controlOP2:= false;
end;
end;
procedure cargaOP2();
var
sinn,cods:string;
begin
if controlOP2() then
begin
writeln('Archivo vacio');
i:=-1;
repeat
begin
i:= i + 1;
writeln('ingrese sintomas: ');
readln(sinn);
writeln('ingrse el codigo: ');
readln(cods);
if verifiOP2(sinn) then
begin
seek(sintomas,i);
unsintoma.sin:=sinn;
write(sintomas,unsintoma);
end
else
begin
writeln('ERROR: sintoma ya existente');
end;
writeln('desea ingresar otro sintoma');
writeln('s/n');
readln(elec);
end;
until (elec = 'n') or (i = 4);
end
else
begin
writeln('Ya hay sintomas cargados');
// mostrarOP2();
writeln('desea ingresar nuevos sintomas?');
writeln('s/n');
readln(elec);
i:= filesize(sintomas) - 1;
while elec='s' do
begin
i:=i+1;
writeln('ingrese el nombre de sintoma');
readln(unsintoma.sin);
writeln('ingrse el codigo: ');
readln(unsintoma.codsin);
if verifiOP2(sinn) then
begin
seek(sintomas,i);
write(sintomas,unsintoma);
end
else
begin
writeln('ERROR: sintoma ya existente');
end;
writeln('desea ingresar otro sintoma');
writeln('s/n');
readln(elec);
end;
end;
end;
procedure OPCION_2();
begin
cargaOP2();
end;
procedure OPCIONES();
begin
writeln('ingre op');
readln(opcion);
while (opcion <> 0) do
if (opcion <= 6) and (opcion > 0) then
begin
case opcion of
1: OPCION_1();
2: OPCION_2();
// '3': OPCION_3();
// '4': OPCION_4();
// '5': OPCION_5();
// '6': OPCION_6();
end;
writeln(' desesa ingresar otra opcion');
readln(deseo);
if (deseo = 'si') then
clrscr;
readln(opcion);
end
else
begin
writeln('Codigo de opcion incorrecto, ingrese un codigo valido');
readln(opcion);
end;
end;
begin
// seleccion de idioma
creaarchi();
asignaGRAL();
OPCIONES();
end.
Valora esta pregunta


0