在终端输入参数,然后控制显示:
#include <stdio.h> #include <unistd.h> int main(int argc, char *argv[]){ int c; while((c = getopt(argc,argv, "t:a:")) != -1){ switch(c){ case 't': printf("%s \n", optarg); break; case 'a': printf("%s \n", optarg); break; default: break; } } return 0; }
执行后显示:
[www@zhoubc mem]$ ./a.out -aall -ttest all test