2009年(33)
分类: LINUX
2009-06-13 17:14:58
|
gcc pz.c -o pz
输入:pz -i -f fuck you all -rl "hi there"
输出:
ret = i, optopt = ?, optind = 2, optarg: (null)
ret = f, optopt = ?, optind = 4, optarg: fuck
ret = r, optopt = ?, optind = 6, optarg: (null)
ret = l, optopt = ?, optind = 7, optarg: (null)
other arguments:
you, 5
all, 6
hi there, 7
发现规律:
调整前
pz -i -f fuck you all -rl "hi there"
0 1 2 3 4 5 6 7
调整后
pz -i -f fuck -rl you all "hi there"
0 1 2 3 4 5 6 7
开始:
(当前序号)选项, optind
(1)i, 2
(2)f, 4
(发现4,5都不行,6行)
(6)r, 6
(6)l, 7
(遍历完,进行调整)
optind指向调整后的第一个“其他参数”的序号