#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
int opt;
for(opt = 0 ; opt < argc ; opt++)
printf("argv[%d] = %s
" , opt, argv[opt]);
printf("argc = %d " , argc);
return 0;
}
执行结果:
]# ./a.out -a 100 -b 200 -c 300
argv[0]=./a.out
argv[1]=-a
argv[2]=100
argv[3]=-b
argv[4]=200
argv[5]=-c
argv[6]=300
argc = 7