Forum > Beginners
Record type file doesn't print integer data properly
Zilveztre:
As the title says, the program asks you to put some numbers (on a record) than later on is written on a file. But when it gets to the point of printing that record(tSiemCos) it prints a bunch of symbols without any meaning... what am I doing wrong? %)
Type declaration:
--- Code: ---Type
tCult= record
codEsp: integer;
nomb: string[15];
resist: string[15];
metod: string[10];
mes: integer;
dia: integer;
end;
tSiemCos= record
codEsp: integer;
anio: integer;
mes: integer;
dia: integer;
cant: integer;
end;
tArchCult= File of tCult;
tArchSiemCos= File of tSiemCos;
--- End code ---
Procedure that prints the data on screen:
--- Code: ---Procedure mostrarReg(var arch: tArchCult; reg:tSiemCos);
Var
nomb: string;
begin
nomb:= buscaNombre(arch,reg.codEsp);
Writeln(reg.mes, ' ',reg.dia,' ',nomb,' ',reg.cant);
End;
--- End code ---
Thanks a lot!!
howardpc:
What is the code for your buscaNombre() function?
eny:
Please show the entire program that asks for input, writes it to a file and reads it back.
My crystal ball is at the repair shop (high mileage; needs a big overhaul).
Zilveztre:
--- Quote from: eny on November 22, 2014, 10:59:27 pm ---Please show the entire program that asks for input, writes it to a file and reads it back.
My crystal ball is at the repair shop (high mileage; needs a big overhaul).
--- End quote ---
Is a 1000 line code, you really want me to post it here? xD. My question was simple enough. But well... I have here the extracts from the code that loads the data and writes it on the file:
This is the one that asks the data of the record:
--- Code: ---Procedure cosecha(c, c1: string);
Var
archCult: tArchCult;
arch: tArchSiemCos;
reg: tSiemCos;
clave: integer;
begin
Assign(arch, c1);
reset(arch);
Assign(archCult, c);
Reset(archCult);
If (FileSize(archCult)>=0) then
begin
Repeat
begin
Write('Ingrese el codigo de especie: ');
Read(clave);
If existeCult(archCult, clave) then
begin
reg.codEsp:= clave;
completaCosecha(reg);
insertaReg(arch, reg);
end
else
Writeln('No existe Cultivo');
end;
Until confirma('Finalizar? (S/N)');
end
else
Writeln('No hay Cultivos activos');
Close(arch);
Close(archCult);
end;
--- End code ---
Now the function that makes sure that the data we're entering is valid (checking on another file)
--- Code: ---Function existeCult(var arch: tArchCult; clave: integer): boolean;
Var
regCu: tCult;
existe: boolean;
begin
existe:= false;
Seek(arch, 0);
Read(arch, regCu);
While (not existe and not Eof(arch)) do
begin
If (clave<>regCu.codEsp) then
Read(arch, regCu)
else
existe:= true;
end;
existeCult:= existe;
end;
--- End code ---
In this one the record is filled:
--- Code: ---Procedure completaCosecha(reg: tSiemCos);
Var
a, m, d: integer;
begin
Repeat
begin
Repeat
begin
Write('Ingrese el anio de la cosecha: ');
Read(a);
m:= enteroEnRango('Ingresar el mes de la cosecha: ', 1, 12);
d:= enteroEnRango('Ingresar el dia de la cosecha: ', 1, 31);
end;
Until fechaValida(a, m, d);
Writeln ('Anio: ',a, ', Mes: ', m, ', Dia: ', d);
end;
Until confirma('Finalizar? (S/N)');
reg.anio:=a;
reg.mes:=m;
reg.dia:=d;
Write('Ingresar las unidades cosechadas: ');
Repeat
Read(reg.cant);
Until reg.cant>0;
end;
--- End code ---
This one is the one that writes the record on the file in the correct orde (for the listing afterwards):
--- Code: ---Procedure insertaReg(var arch: tArchSiemCos; regN: tSiemCos);
(* Inserta en el archivo el registro nuevo respetando el orden (por año y mes).
Precondición: arch= Archivo ordenado. Ingresado como parámetro.
regN= Registro nuevo a insertar de manera ordenada en el archivo.
Poscondición: arch= Ordenado y con regN insertado en su orden.
*)
Var
reg: tSiemCos;
pos: integer;
encontrePos: boolean;
begin
pos:= FileSize(arch) - 1;
encontrePos:= False;
if (not eof(arch)) then // Entra si el archivo no esta vacío
begin
While (pos>=0)and(not encontrePos) do
begin
Seek(arch, pos);
read(arch, reg);
If (reg.anio>regN.anio) then
begin
Write(arch, reg);
pos:= pos - 1;
end
else
begin
If (reg.anio=regN.anio) then
begin
If (reg.mes>regN.mes) then
begin
Write(arch, reg);
pos:= pos - 1;
end
else
begin
If (reg.mes=regN.mes) then
begin
If (reg.dia>regN.dia) then
begin
Write(arch, reg);
pos:= pos - 1;
end
else
begin
If (reg.dia=regN.dia) then
begin
If (reg.codEsp>regN.codEsp) then
begin
Write(arch, reg);
pos:= pos - 1;
end
else
begin
If (reg.codEsp=regN.codEsp) then
begin
Seek(arch, pos);
Write(arch, reg);
end
else
encontrePos:= True;
end;
end
else
encontrePos:= True;
end;
end
else
encontrePos:= True;
end;
end
else
encontrePos:= True;
end;
end;
end
else // Si el archivo esta vacío...
Write(arch, reg); // Escribe el primer registro ingresado al archivo.
end;
--- End code ---
This is the one that prints on the screen in order:
--- Code: ---Procedure listaCos(c1, c2: string);
(* Lista las cosechas ordenadas por código de especie, año y mes.
Precondición: c1, c2= Nombre de los archivos necesarios a abrir para recuperar datos.
Poscondición: --
*)
Const
tope=30;
Var
archCu: tArchCult;
archCos: tArchSiemCos;
regCos, ant: tSiemCos;
cMes, cEsp, hojas, lineas: integer;
begin
cEsp:= 0;
cMes:= 0;
hojas:= 0;
Assign(archCu, c1);
Reset(archCu);
Assign(archCos, c2);
Reset(archCos);
iniciaAnterior(archCos, ant); // This procedure copies the first record on the file for the control breaks of the list
Seek(archCos, 0);
encabezadoAnio(ant.anio, hojas, lineas);
encabezadoCos(lineas);
While not Eof(archCos) do
begin
Read(archCos, regCos);
If (regCos.codEsp<>ant.codEsp) then
begin
subtotalMes('Subtotal mes: ', cMes, cEsp, lineas);
subtotalEsp('Subtotal especie: ', cEsp, lineas);
encabezadoCos(lineas);
end
else
begin
if (regCos.mes<>ant.mes) then
begin
subtotalMes('Subtotal mes: ', cMes, cEsp, lineas);
encabezadoCos(lineas);
end;
end;
ant:= regCos;
If (lineas>tope) then
begin
pieDePagina();
encabezadoAnio(regCos.anio, hojas, lineas);
encabezadoCos(lineas);
end;
mostrarReg(archCu, regCos);
lineas:= lineas + 1;
cMes:= cMes + 1;
end;
subtotalMes('Subtotal mes: ', cMes, cEsp, lineas);
subtotalEsp('Subtotal especie: ', cEsp, lineas);
Close(archCu);
Close(archCos);
End;
--- End code ---
And this is what I get on cmd:
http://imagizer.imageshack.us/a/img540/2472/xx7Lce.jpg
howardpc:
--- Quote from: Zilveztre on November 23, 2014, 07:21:37 am ---My question was simple enough. But well... I have here the extracts
--- End quote ---
Simple answer: you are both the author and have all the code (the design, the full picture), and cannot successfully debug it. Yet you expect others who have never seen most of your code to divine where the error(s) are by looking at fragments?
With some puzzles (deciphering the Dead Sea Scrolls, for example) you may be restricted to fragments. But not in this case.
Navigation
[0] Message Index
[#] Next page