Click here to Skip to main content
15,885,818 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I'm trying to create a 2D grid for the following command line argument, but I can't seem to figure out how to run it within a Putty terminal:
C++
if (argc!=2){
        cerr << "No maze size entered." <<endl;
        return -1;
    }

    if ((n = atoi(argv[1]))==0 || n<4){
        cerr << "Incorrect maze size entered." <<endl;
        return -1;
    }

After compiling my file should it be somthing like ./a.out 5...? Any help would be appreciated.

What I have tried:

I tried running main after compiling with:

a.out 5 5 :"No map size entered"
./a.out 5 : Memory leak, program loops
./a.out 5 5:"No map size entered"
Posted
Updated 23-May-16 11:48am
v2
Comments
Sergey Alexandrovich Kryukov 22-May-16 16:51pm    
What do you mean by "running an argument"? A command-line argument is the part of the string followed by the name of your program file name when you start it. Did you know that? Is it your program? If it yours, you should know better what do you expect for command line, how you handle it and how you process invalid command-line input.
—SA
Richard MacCutchan 23-May-16 3:26am    
Why are the error messages on the console different from the ones in your code?

a.out 5 5 :"No map size entered"

This is quite clear (beside that the message text differs from the one printed by your code as already mentioned by Richard). Your code checks if exactly one argument has been passed and terminates when argc is not 2.

With the above commands argc is 3 and argv[0] = "a.out", argv[1] = "5", and argv[2] is "5".

So you may rewritre your check to give more detailed messages:

if (argc < 2)
{
    cerr << "No maze size entered." <<endl;
    return -1;
}
else if (argc > 2)
{
    cerr << "Too many arguments." <<endl;
    return -1;
}


./a.out 5 : Memory leak, program loops

You did not show the code that generates this message. At least the tests shown in your question has been passed.
 
Share this answer
 
./a.out 5 : Memory leak, program loops

This is the correct command line, so it succesfully pass your checks. However your program fails in the later Steps (you didn't post such code).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900