-3

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?

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Isha
  • 3
  • 4
  • 1
    [not the problem] `void main` is wrong. `main` must always return an `int` – NathanOliver Jan 20 '16 at 16:21
  • 3
    How are you running your program? It sounds like you're looking for command line parameters but you haven't actually given any. If you had then argc/argv would have that data. – Retired Ninja Jan 20 '16 at 16:23
  • 1
    For a program with two arguments `argc` will be 3! – Sebastian Stigler Jan 20 '16 at 16:28
  • As above, 2 arguments will make `argc = 3` as the first argument `argv[0]` is always the name used to invoke the executable. However, "How do I make the command prompt stay and give two inputs"? How should we know without you providing any indication of which shell/IDE/debugger you are using? In simple terms, you just run the executable with those arguments, but we don't know what you're using to run it, which might change the answer significantly. – underscore_d Jan 20 '16 at 16:29

2 Answers2

1

argc is taken from what you type at the command prompt. There isn't enough info here to see what the name of the executable is, but let's say foo. Then

% foo # argc == 1
% foo banana # argc == 2, etc.
Andrew Lazarus
  • 18,205
  • 3
  • 35
  • 53
0

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

Muhammad Zeeshan
  • 470
  • 7
  • 24