In my program, I'm declarign a character array holding the location of a config file, it should be something like: "/home/user/.config"
now I understand the longest username can be 32 bytes long(GNU Linux), so I know that array will not hold more than 46 characters, in this case should I be using malloc or not.
should I use:
char config_file_location[46];
strcpy (config_file_location, getenv("HOME"));
strcat(config_file_location,"/.config");
or:
char *config_file_location;
config_file_location = (char *) malloc(43);
strcpy (config_file_location, getenv("HOME"));
strcat(config_file_location,"/.config");
//code goes here
free(config_file_location);
also should I use realloc in the above example to get the config_file_location to use exactly the amount of memory it is supposed to?
I'm looking for best practice info, if it is not worth doing in this case, I would like to know when it would be, and I would like to know the reason behind which approach is better.
Thanks I appreciate it.