You need to create an array of pointers to mutable strings, terminated with NULL
. Remember also that argv[0]
represents the program name, not a supplied argument. For example, if you want netcat to behave as if it was invoked with the command nc -l -p 80
, you could do:
char arg0[] = "nc";
char arg1[] = "-l";
char arg2[] = "-p";
char arg3[] = "80";
char *fixed_argv[] = { arg0, arg1, arg2, arg3, NULL };
argc = 4;
argv = fixed_argv;