1 int main(int argc, char * argv[])
argc: argument count
argv:argument vector
其中,
char * argv[] 指针数组
char * argv[] | char ** argv | char argv[][] 三种写法都可以.
环境:Linux CentOS 2.6.32-358.2.1.el6.i686
code :foo.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) { int i = 0;
if(argc < 2) fprintf(stderr,"usage: %s",argv(0));
for(; i<argc; i++) printf("vector %d : %s ", i, argv[i]); return 0; }
# make foo
# ./foo 1 0xFF aBc
结果:
vector 0 : ./foo vector 1 : 1 vector 2 : 0xFF vector 3 : aBc