Probaste escribiendo campo por campo con fwrite? Creo que el problema puede
ser intentar escribir todo el registro junto.
Tal vez:
fwrite(&(reg1->nro), sizeof(int), 1, p);
fwrite(&(reg1->letra), sizeof(char), 1, p);
Saludos
Tito
----- Original Message -----
From: Federico De Seta
To: [email protected]
Sent: Wednesday, March 19, 2008 10:33 AM
Subject: [Prog] problema valgrind - byte(s) no inicializados ??
Hola!. Tengo el siguiente programa:
#include <stdio.h>
#include "stdlib.h"
typedef struct{
int nro;
char letra;
}campo;
int main(int argc, char ** argv)
{
campo *reg1 = (campo*)malloc (sizeof(campo));
reg1->nro = 5 ;
reg1->letra ='g';
FILE* p = fopen("lala.txt", "wb");
fwrite((void*)reg1, sizeof(campo), 1, p);
fclose(p);
free(reg1);
return (0);
}
Cuando lo corro con el valgrind me tira lo siguiente:
==6248== Memcheck, a memory error detector.
==6248== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==6248== Using LibVEX rev 1804, a library for dynamic binary translation.
==6248== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==6248== Using valgrind-3.3.0, a dynamic binary instrumentation framework.
==6248== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==6248== For more details, rerun with: -v
==6248==
==6248== Syscall param write(buf) points to uninitialised byte(s)
==6248== at 0x40E95C3: __write_nocancel (in
/lib/tls/i686/cmov/libc-2.3.6.so)==6248== by 0x408CC8A:
_IO_do_write@@GLIBC_2.1 (in /lib/tls/i686/cmov/libc-2.3.6.so)
==6248== by 0x408C3D4: _IO_file_close_it@@GLIBC_2.1 (in
/lib/tls/i686/cmov/libc-2.3.6.so)
==6248== by 0x408281A: fclose@@GLIBC_2.1 (in
/lib/tls/i686/cmov/libc-2.3.6.so)
==6248== by 0x80484AB: main (main.c:21)
==6248== Address 0x4021005 is not stack'd, malloc'd or (recently) free'd
==6248==
==6248== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 11 from 1)
==6248== malloc/free: in use at exit: 0 bytes in 0 blocks.
==6248== malloc/free: 2 allocs, 2 frees, 360 bytes allocated.
==6248== For counts of detected errors, rerun with: -v
==6248== All heap blocks were freed -- no leaks are possible.
La linea 21 del main es la del fclose. Alguien sabe que puede ser?
Saludos y gracias de antemano por responder.
Fd.
------------------------------------------------------------------------------
Tarjeta de crédito Yahoo! de Banco Supervielle. Solicitá tu nueva Tarjeta de
crédito. De tu PC directo a tu casa.
Visitá www.tuprimeratarjeta.com.ar
------------------------------------------------------------------------------
_______________________________________________
Lista de correo Programacion.
[email protected]
http://listas.fi.uba.ar/mailman/listinfo/programacion
------------------------------------------------------------------------------
No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.7/1335 - Release Date: 19/03/2008
09:54 a.m.
_______________________________________________
Lista de correo Programacion.
[email protected]
http://listas.fi.uba.ar/mailman/listinfo/programacion