如何使用regexp来进行正则表达式的匹配?

escapestar 2000-06-17 05:28:00
如何使用regexp来进行正则表达式的匹配?
下面这个程序有何不妥,请各位打下指正:
#define INIT register char *sp=instring;
#define GETC() (*sp++)
#define PEEKC() (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return;
#define ERROR(c) regerr()
#include <stdio.h>
#include <regexp.h>
main()
{
char expbuf[10];
char linebuf[80];
strcpy(expbuf,"^[0-9]*$");
compile((char *)0,expbuf,&expbuf[sizeof(expbuf)],'\0');
for (;;)
{
printf("please input a string:\n");
scanf("%s\n",linebuf);
if (step(linebuf,expbuf))
{
printf("success!\n");
}
else
printf("failed!\n");
}
}

编译时提示regerr未定义,不知何故?希望各位大虾能以例程解答
请发email至bone_dragon@21cn.com,多谢!
...全文
149 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
solar 2000-06-18
  • 打赏
  • 举报
回复
not regerr,but regerror!
solar 2000-06-18
  • 打赏
  • 举报
回复
also try this example modified from your code. it works on linux(egcs) and solaris(gcc)
-----------------------------------------------
#include <stdio.h>
#include <regex.h>
main()
{
regex_t re;
char *expbuf="^[0-9]*$";
char linebuf[80];
regmatch_t pmatch[16];

regcomp(&re,expbuf,0);
for (;;){
printf("please input a string:\n");
scanf("%s",linebuf);
if(0 == regexec(&re, linebuf, 16,pmatch,0))
printf("success!\n");
else
printf("failed!\n");
}
}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧