hello
i build two separate software simples , one for write one file that i called persona.txt and another for read it
=================================
#include <stdio.h>
#include <stdlib.h>
struct persona {
int numero ;
char *nome ;
char cognome [10] ;
} ;
typedef struct persona persona ;
int main ()
{
FILE *Jtr ;
persona persona ;
fgets (persona.cognome , 9 , stdin) ;
persona.nome = (char*) malloc (sizeof (char ) * 6 ) ;
persona.nome = "tony" ;
fprintf (stdout , "%s" , persona.nome) ;
if ( (Jtr = fopen ("persona.txt" , "wb" ) ) != NULL )
{
fwrite (&persona , sizeof (struct persona ) , 1 , Jtr);
}
fclose (Jtr ) ;
system ("PAUSE") ;
return 0 ;
}
==========================================================
after i try to read that file "persona.txt"
with it
#include <stdio.h>
#include <stdlib.h>
struct persona {
int numero ;
char *nome ;
char cognome [10] ;
} ;
typedef struct persona persona ;
int main ()
{
FILE *Jtr ;
char *Ptr ;
persona persona ;
if ( (Jtr = fopen ("persona.txt" , "rb" ) ) != NULL )
{
persona.nome = (char*) malloc ( sizeof (char) * 10 ) ;
fread (&persona , sizeof (struct persona ) , 1 , Jtr ) ;
fprintf (stdout , "%s\n" , persona .cognome ) ;
fprintf (stdout , "%s\n", persona .nome ) ;
}
fclose (Jtr ) ;
system ("PAUSE") ;
return 0 ;
}
but this software tell me this Error :
"Unhandled exception at 0x64f3984f (msvcr90d.dll) in lettura.c.exe: 0xC0000005: Access violation reading location 0x00f55758"
i thinked about problem of allocation with function malloc and
the pointer of string "persona.nome" , but i can't resolve!
somebody could help me'
thanks