允许程序有两个可选变元--编译出错

liushac liushac 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
/***********************************************************************
Copyright (c) 2009,liushac
All rights no reserved.

Name: <<C程序设计语言>>例程5-10
ID: hello.c
功能: 允许程序有两个可选变元。其中一个表示“与模式串不匹配的文本行”,
另一个表示“每个被打印文本行前面都有相应的行号”。
-x(x代表except)表示打印所有与模式串不匹配的文本行;
-n(n代表number)表示打印行号。

Version: 0.1
Author: c.
Date: Sep 25, 2009

***********************************************************************/
#include <stdio.h>
#include <string.h>
#define MAXLINE 1000

int getline(char *line,int max);

main(int agrc,char *argv[])
{
char *line;

long lineno=0;
int c,except=0,number=0,found=0;

while(--argc>0 && (* ++argv)[0]=='-')
{
while(c=*++argv[0])
switch(0)
{
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("%d:",lineno);
printf("%s",line);
found++;
}
}
return found;
}
}
/* getline: 将一行读入s中并返回其长度 */
int getline(char *s, int lim)
{
char *p;
int c;

p = s;
while (--lim > 0 && (c = getchar()) != EOF && c != '\n')
*p++ = c;
if (c == '\n')
*p++ = c;
*p = '\0';
return (int)(p - s);
}


出错提示:
--------------------Configuration: hello - Win32 Debug--------------------
Compiling...
hello.c
D:\Dev-Cpp\hello.c(14) : error C2065: 'argc' : undeclared identifier
D:\Dev-Cpp\hello.c(34) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'char '
D:\Dev-Cpp\hello.c(34) : warning C4024: 'getline' : different types for formal and actual parameter 1
D:\Dev-Cpp\hello.c(37) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char '
D:\Dev-Cpp\hello.c(37) : warning C4024: 'strstr' : different types for formal and actual parameter 1
执行 cl.exe 时出错.

hello.obj - 1 error(s), 0 warning(s)
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
liushac
C语言 70,039 成员 243,237 内容