Could someone help explaining why this part of my code isn't working?
typedef struct {
char *something;
} random;
random *rd;
rd->something = calloc(40, sizeof(char)); // This is the line which crashes
strncpy(rd->something, aChar, 40);
The program works if I write it as such:
random rd;
rd.something = calloc(40, sizeof(char));
strncpy(rd.something, aChar, 40);
But I think this is wrong when handling memory, that's why I want help with the first scenario.