OK, I am working on a relatively big program, one that scans for directories and prints them nicely to a file, depending on many options that the user types at the command line.

So the first thing I do is parse the options to a structure that contains many bool variables. The structure looks like this:

Code:
typedef struct arguments{
	bool help;
	bool recurse;
	bool complete;
	bool output;
	bool verbose;
	bool each_folder;
	unsigned int other;
	char filepath_arg[MAX_DIR_LENGTH];
} DIR_OPTIONS;
That structure is in a header file. And the bool variables will turn on or off many if()'s on the program, which will implement the options. My problem is that my source code is divided in many modules, the main module which basically parses the arguments and starts the dir scanning engine, which is in module dir.c that calls another module fileinit.c which initializes the file (or files) that will be written. So somehow, I have to pass the arguments to the other functions.

First thing I thought was making the structure global:
Code:
DIR_OPTIONS options={0,0,0,0,0,0} //init as false

int main(int argc, char *argv[])
{
     ......
}
And in the other modules:

Code:
extern DIR_OPTIONS options;
My solution works, but I don't know... I have seen absolutely no program that does this. But I have seen many programs that use pointers to pass options.

So, I tried something like this:

Code:
int main(int argc,char *argv[])
{
	DIR_OPTIONS *options;
	options=(DIR_OPTIONS *)malloc(sizeof(DIR_OPTIONS)); //allocate memory for the function
	dir(options);
}

void dir(DIR_OPTIONS *options)
{
	...
}
But it simply doesn't work. For some reason the compiler gives me errors if I try to do something like
Code:
*options={0,0,0,0,0,0};
and... it simply doesn't work. The program stops and the file it is supposed to write has nothing in it.

So my big question is: How can I create a structure in the main() function, and pass it to other functions as a pointer? I don't want the recursive dir() function taking up stack space because of declaring a DIR_OPTIONS struct in it, so I just want to pass dir() a pointer. And I just don't want to make it global-external.

Thanks a lot!!!

P.S: Is there a reason why (apparently) global variables are not preferred? Or are they completely fine?