I'm creating dynamic arrays with the length of a name inputed by the user, but when I want to free()
the memory allocated with malloc()
it's giving me a "Debug error"
typedef struct
{
char *nombre;
float nota;
} tficha;
tficha leeFicha()
{
char nombreTam[100];
int tamNombre;
tficha ficha;
scanf("%s",nombreTam);
tamNombre=strlen(nombreTam);
ficha.nombre=(char *)malloc(tamNombre*sizeof(char));
strcpy(ficha.nombre,nombreTam);
free(ficha.nombre); // Here is giving me a Debug Error (HEAP CORRUPTION DETECTED: after Normal block (#166) at 0x0065C450. CRT detected that the application wrote to memory after end of heap buffer.)
return ficha;
}
How can I free ficha.nombre
without errors?