请问 如下程序中的-n和-x有什么用呢?看不太懂啊,谢谢

来源:百度知道 编辑:UC知道 时间:2024/09/21 22:27:06
#include <stdio.h>
#include <string.h>
#define MAXLINE 1000

int getline(char *line, int max);

/* find: print lines that match pattern from 1st arg */
main(int argc, char *argv[])
{
char line[MAXLINE];
long lineno = 0;
int c, except = 0, number = 0, found = 0;

while (--argc > 0 && (*++argv)[0] == '-')
while (c = *++argv[0])
switch (c) {
case 'x':
except = 1;
break;
case 'n':
number = 1;
break;
default:
printf("find: illegal option %c\n", c);
argc = 0;
found = -1;
break;
}
if (argc != 1)
printf("Usage: find -x -n pattern\n");
else
while (getline(line, MAXLINE) > 0) {
lineno++;
if ((strstr(line, *argv) != NULL) != except) {
if (number)
printf("%ld:", lineno);
printf("%s", line);
fou

看while循环
case 'x':
except = 1;
break;
case 'n':
number = 1;
就是这里了,当你运行 find -x 时 except=1,find -n 时,number=1。也就是给find程序定义了两个参数 -x -n。

就像是在dos命令中输入的命令参数一样的.根据这两个参数来确定进行什么操作.