Q:

How do I find out how many arguments are being passed

I am writing some C code on Linux.  I want to loop through the *argv[] parameter being passed to main, but I don't know how to stop before getting a seg fault.
  i = 0;
  while (i < sizeof(argv)) {
    printf("%s\n", argv[i]);
    i ++;
  }

This produces a seg fault because sizeof always returns 8.  How do I get the actual number of elements in argv, or apply some kind of test to stop at the end of argv?

A:

The first argument of main is argc which is the number of arguments passed to your program. This is at least 1, which is the name of the executable.
#include <stdio.h>

int main(int argc, char *argv[])
{
  printf("%d\n", argc);
  return 0;
}

Invoked as:
$ ./a.out 
1
$ ./a.out 1 2 3 4
5
$ ./a.out 1 2 3
4

A:

The first argument.. argc  should already have the CLI argument count.. Any reason why that isn't used?
int main(int argc, char** argv)
{
    if(argc > 1)
 }

