允许程序有两个可选变元--编译出错
/***********************************************************************
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)
...全文
相关推荐
为什么debug编译不出错,而release编译会出错
在 Debug 模式下,编译器会插入调试信息,以便于开发者调试程序;而在 Release 模式下,编译器会优化代码,删除调试信息,以提高程序的运行速度。
C语言 编译出错信息一览表
在使用像Turbo C这样的编译器时,编译器会按照错误类型依次输出错误信息,包括文件名、出错行号以及错误内容,帮助程序员更有效地调试代码。
matlab2014b 完全破解文件,解决编译exe程序出错的问题
完美破解matlab2014b,可以解决编译成exe程序出错的问题
编译课程设计带出错处理程序的算符优先算法.doc
《编译课程设计:带出错处理程序的算符优先算法》编译课程设计的主要目标是实现一个带有出错处理程序的算符优先分析算法。这种算法在解析编程语言的表达式时起着关键作用,它能有效地识别并处理语法错误。
了解中间代码生成是编译程序的一个可选阶段
中间代码生成是编译程序设计中的一个重要环节,它在源代码到目标代码的转化过程中起着桥梁作用。


