Command Line Argument problem

Hello everyone, I am trying to make an array of size "N" for a school homework assignment involving sorting large arrays. My teacher says to use the command line to get the value n.

I asked about it and they recommended that argv[1] will have the value I want.

my problem is that every time I try to access element 1 of char * argv[] my program completely crashes.

here's how I'm going about it:

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <iostream>
#include <stdlib.h>

using std::cout;

int main(int argc, char * argv[])
{
   int n;
   n = atoi(argv[1]); // this is where it crashes!

}


Anybody know why this happens and how I can fix it? I can't start my project until I can make an array of size n! Thanks in advance.
┬┐Did you provide that argument?
$ ./a.out 42
hmm... No I didn't do anything like that. How do I go about that if you don't mind explaining?
That's how you execute the program...
Assuming that you use Windows http://www.indigorose.com/webhelp/vp/Windows_Basics/Command_Line_Arguments.htm
SO I have to execute my program from the command line to pass in an argument at all?
Topic archived. No new replies allowed.