How to remove the head of the main function?

I am trying to move some code from a separate binary and have it inside my main program. Unfortunately, I cannot simulate initialization variables for the main function.

How can I create argcand argvmanually? Can someone give me some examples of appointments.

as it looks like this:

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

I decided that I could assign them as follows:

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

But that will not work. Can someone tell me how to do this?

+3
source share
4 answers
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);
+6
source

The last element of the array argv[]is actually argv[argc]a pointer NULL.

:

char *argv[] = { "first", "second", NULL }; 
int argc = sizeof(argv) / sizeof(*argv) - 1;
+1

. .

+1

Why would you do this? If you are using an IDE, then it will be able to add a command line parameter. If you call the program directly, just call it using the command options

0
source

Source: https://habr.com/ru/post/1739011/


All Articles