driedupsharpie
driedupsharpie

Reputation: 143

Finding the Number of Elements in an Array of Command Line Arguments?

I'm working off of a Linux command line with g++ and the code will be executed like so:

./mycode arg1 arg2 arg3 ... 

This works fine as I am using the array argv[] and the following for main:

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

However there is a part of my program where I need to know the number of command line arguments given. sizeof() is failing me here. Any ideas of how this could be accomplished?

Upvotes: 0

Views: 219

Answers (1)

Ohad Eytan
Ohad Eytan

Reputation: 8464

This is what the argc parameter is meant for - it is the ARGument Count of the argv (ARGument Value) array.

Upvotes: 2

Related Questions