
1:明确的输入、输出,比如输入输出数据;
2:进程序列;
3:如有图形界面,当如有图形界面未必表示运行成功;
最后:你需要几个因素综合考虑,你写C语言程序,可以使用调试工具(gdb)跟踪
;写程序需要慢慢积累经验;当然灵感很重要!
/* 一组宏定义,不过此函数没有用 */#define ESIZE 1024
#define INIT register unsigned char *sp=instring
#define GETC() (*sp++)
#define PEEKC() (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return c
#define ERROR(c) { regerr(c)return(NULL)}
#include "stdio.h"
#include "string.h"
/* 这是什么头文件?? */
#include "regexp.h"
/* 此文件内定义的全局变量 */
int i
unsigned char *nextpos
static unsigned char lbuf[512], ebuf[ESIZE]
FILE *fp
/* 函数声明 */
int regerr()
/* 可接受命令行参数 */
int main(int argc,char *argv[])
{
if(argc <3) /* 输入的参数不足三个,出错 */
{
/* 向标准出错设备输出信息 */
fprintf(stderr,"Use: %s regular_expr files ..\n",argv[0])
exit(-1)/* 退出程序 */
}
/* 没见过compile函数 */
nextpos = compile(argv[1], ebuf, &ebuf[ESIZE],'\0')
if(nextpos)
for(i=2i<argci++)
{
if((fp=fopen(argv[i],"rb"))==NULL)
printf("%s: read failure.\n",argv[i])
else
/* 没见过step函数 */
while(fgets(lbuf,sizeof(lbuf),fp))
if(step(lbuf,ebuf)) printf("%s: %s",argv[i],lbuf)
fclose(fp)/* 关闭文件 */
}
}
/* 向标准出错设备输出信息,即屏幕 */
int regerr(int c) /* 函数不完整,返回值没用 */
{
fprintf(stderr,"Error %d.\n", c)
}
grep的功能
grep从一个或多个文本文件中查找符合指定范本(正则表达式)的行,并把查找结果输出到指定设备(默认到屏幕)。
正则表达式?还要模式匹配?有点小复杂啊。。。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)