Search code examples
c++exitargc

How is the ARGC value initialized if I don't enter it in the command prompt?


When I run the following code:

void main(int argc, char** argv)
{

    if (argc != 2){
        fprintf(stderr, "Usage: %s video-dir-path\n", argv[0]);

        exit(-1);
    }


    XFishTracker ft(argv[1]);

    int id = 0;

    while (true)
    {
        id++;
...
...

It exits since the value of ARGC is obviously NOT 2. If I comment out the exit (-1) line, I get an ASSERTION ERROR. I think because the ARGC isn't 2, my program does not run or proceed. How do I initialize argc to 2 and make the program run, when it exits before I can even see the command prompt properly.

How do I make the command prompt stay and give two inputs so that argc == 2?


Solution

  • It seems you haven't given any command line argument, that's why you are getting nothing in argc and argv.

    Well you can give any number of command line arguments. If you are using Visual Studio, go to project properties -> Debugging. There you can see a box "Command line arguments" Give as many as you want