#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\n" , opt, argv[opt]);
printf("argc = %d\n" , 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
时间: 2024-10-03 10:31:47