hi i have a problem when i use free with a structure inside a structure ...this is the code...
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char *table_name;
int id_client[10];
} TABLE;
typedef struct
{
char *db_name;
TABLE *db_table;
} DB_RESOURCE;
int main(int argc, char **argv)
{
DB_RESOURCE *db_list;
char dbname[] = "database1";
char dbtable[] = "table1";
db_list = (DB_RESOURCE *)malloc(sizeof(DB_RESOURCE)); // te lo dichiara di 1
db_list[0].db_name = (char *) malloc(sizeof(dbname));
db_list[0].db_table = (TABLE *) malloc(sizeof(TABLE));
db_list[0].db_table[0].table_name = (char *) malloc(sizeof(dbtable));
strcpy(db_list[0].db_name, "database1");
strcpy(db_list[0].db_table[0].table_name, "table1");
db_list[0].db_table[0].id_client[0] = 28;
printf("\n%s\n", db_list[0].db_name);
printf("\n%s\n", db_list[0].db_table[0].table_name);
printf("\n%ld\n", db_list->db_table->id_client[0]);
free(db_list[0].db_name);
free(db_list[0].db_table[0].table_name);
free(db_list->db_table->id_client);
printf("\n**** before the free ****\n");
printf("\n%s\n", db_list[0].db_name);
printf("\n%s\n", db_list[0].db_table[0].table_name);
printf("\n%ld\n", db_list[0].db_table[0].id_client[0]);
return 0;
}
and when i execute the program the latest free() does'nt have effect in fact the output is :
database1
table1
28
**** dopo la free ****
database1
hó@
28
help please....i don't know because i have this problem.....
Please use [code][/code]Tags