Search code examples
cparametersprogram-entry-pointargvargc

How can I remove the head of a main function?


I am trying to move some code from a separate binary and have it inside my main program. Unfortunately I can't mimic the initialization variables for the main function.

How can I create argc and argv by hand? Can someone give me some example assignments.

since it looks like this:

int main(int argc, char *argv[])

I figured I could assign them like this:

int argc=1;
char *argv[0]="Example";

But it doesn't work. Can anyone tell me how this might be done?


Solution

  • int argc = 3;
    char *argv[4];
    argv[0] = "fake /path/to/my/program";
    argv[1] = "fake arg 1";
    argv[2] = "fake arg 2";
    argv[3] = NULL;
    fakemain(argc, argv);