#include "options.h"
externstruct Options *opt;
void test(void)
{
initilizeOptions();
printf("%s\r\n", opt->firstNames[0]);
printf("%s\r\n", opt->firstNames[1]);
printf("%s\r\n", opt->firstNames[2]);
printf("%s\r\n", opt->firstNames[3]);
/*
Prints:
Adam
David
Michael
Johnathan
*/
}
test();
MY QUESTION:
Am I calloc'ing correctly? The way in which I'm doing this, is it reserving enough memory for the first names? I'm confused on how I am allocating enough memory for, let's say "Adam" as I am if it were "Rumplestiltskin".
Thanks for viewing and look forward for thoughts and advice.
Your program should not link. There is no global opt variable defined. The one defined in initilizeOptions is local and stops existing when the function returns (leaking all memory allocated therein.)
Your program should not link. There is no global opt variable defined. The one defined in initilizeOptions is local and stops existing when the function returns (leaking all memory allocated therein.)
Made a slight mistake in the code. I had put struct Options *opt = NULL; inside the function when in reality it's not. (I edited the post to show correctly).
Yes, everything works fine, I was mainly concerned if I was allocating memory correctly. Thanks all for the replies!