I'm trying to initialize the struct values with init() function.
It looks good but somehow it don't assign it when the execution of the init() function is over. Futhermore, inside the init() function everything is ok but when it returns the assigned values are gone. I spent a few hours but can't figure out what is happening.
Here is my code and struct:
typedef struct svm_data
{
int num_points;
int num_dimensions;
double* training_set;
double* descision_set;
} svm_data_t;
void init()
{
init_data(&test_data);
init_data(&check_data);
printf("in init: test_data->num_dimensions: %d\n", test_data.num_dimensions);
printf("in init: check_data->num_dimensions: %d\n", check_data.num_dimensions);
set_correct_descision_set(&check_data);
}
void init_svm_data(svm_data_t* data)
{
int np = 3;
int nd = 3;
data = (void*)malloc(sizeof(svm_data_t));
data->num_points = np;
data->num_dimensions = nd;
data->training_set = (void*)malloc(sizeof(double)*(NUM_DIMENSIONS+1));
data->descision_set = (void*)malloc(sizeof(double)*(NUM_DIMENSIONS+1));
printf("test_data->num_dimensions: %d\n", data->num_dimensions);
}
This prints:
test_data->num_dimensions: 3
test_data->num_dimensions: 3
in init: test_data->num_dimensions: 0
in init: check_data->num_dimensions: 0
But I want it to print
test_data->num_dimensions: 3
test_data->num_dimensions: 3
in init: test_data->num_dimensions: 3
in init: check_data->num_dimensions: 3
I can't understand what I'm doing wrong. Please help.