Using C, writing it in Linux, Compiling with GCC. I'm having a wierd problem with structs. The structs are defined in public.h, data is written to them in main.c, but comes out very odd when read in public.c.
output
Code:
debug level: 134515272
debug level: 0.000000
port: -18390300
debug level: 2532503
debug level: 0.000000
port: 2866320
debug level: 2532503
debug level: 0.000000
port: 2866320
debug level: 2532503
debug level: 0.000000
port: 2866320
inc/public.h
Code:
***
struct options_t {
int debug;
};
struct arguments_t
{
char *args[2];
int port;
};
***
src/main.c
Code:
int main (int argc, char **argv)
{
struct arguments_t s_arguments;
struct options_t s_options;
// set defaults
s_arguments.port = 0;
s_options.debug = 1;
printf("%i\n", s_options.debug);
debug("Parsing command line arguments...\n");
argp_parse (&argp, argc, argv, 0, 0, &s_arguments);
return 0;
}
src/public.c
Code:
void error ( const char *error_message ) {
printf("\nERROR: %s \n\n", error_message );
exit(0);
}
void debug ( const char *debug_message ) {
struct options_t s_options;
struct arguments_t s_arguments;
printf("debug level: %i\n", s_options.debug);
printf("debug level: %f\n", s_options.debug);
printf("port: %i\n", s_arguments.port);
if (s_options.debug == 1)
printf("\nDEBUG: %s\n", debug_message );
}
Any help is greatly appreciated. Many thanks.