[newbie] about command line arguments

Z

Zoran Cutura

Zoran Cutura said:
Here is an unbfuscated version of this code:
#include <stdio.h>

int func(void);

int main(const int argc, char **argv)
{
static st_argc;
I meant
static int st_argc;
static char** st_argv;

if (st_argv == 0) { /* at startup remember argc and argv */
st_argc = argc;
st_argv = argv;
} else {

/* assume that am called from within program! */
if (argv == 0) /* initially called back from function */
return st_argc; /* return initial argc */

if (argc > 0) {
*argv = st_argv[argc-1];
}

return 0;
}

func();

/* here do all the other stuff main needs to do */

return 0;
}

int func(void)
{
int main_argc, i;
char *nextarg;

main_argc = main(0, 0); /* initial call needs to pass 0 in argv!! */

for(i = 0; i < main_argc; i++) {
main(i+1, nextarg);
main(i+1, &nextarg);
puts(nextarg); /* here is where the arguments can be used! */
}

return 0;
}

I should have compiled befor posting!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,073
Messages
2,570,539
Members
47,197
Latest member
NDTShavonn

Latest Threads

Top