I am C begginer, I was trying to create a function that modify the content of a struct pointer, but it couldn't make it, instead, the content remains the same.
Here my code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int age;
int code;
}person;
void enter(person *struct_pointer);
void main(void)
{
person *person_1 = NULL;
enter(person_1);
printf("CODE: %i\n", person_1->code);
free(person_1);
}
void enter(person *struct_pointer)
{
struct_pointer = malloc(sizeof(*struct_pointer));
struct_pointer->age = 10;
struct_pointer->code = 5090;
}
In the example above when I print code of person_1 it does not print nothing, so I assume is because person_1 is still pointing to NULL.
Can someone pls explain how can I do this, and if it cannot be made why.
Thanks