正则 在gcc3.4.4怎么出现segmentation f
c语言吧
全部回复
仅看楼主
level 7
偶尔惊悚 楼主
这个例子是网上的,不过我在gcc3.4.4下运行 输出”hhh Segmentation Fault”为什么?
2013年06月07日 13点06分 1
level 7
偶尔惊悚 楼主
1#include<stdio.h>
2#include<sys/types.h>
3#include<regex.h>
4#include<memory.h>
5#include<stdlib.h>
6
7intmain(){
8
9char*bematch="[email protected]";
10char*pattern="h{3,10}(.*)@.{5}.(.*)";
11charerrbuf[1024];
12charmatch[100];
13regex_t reg;
14interr,nm=10;
15regmatch_t pmatch[nm];
16
17if(regcomp(®,pattern,REG_EXTENDED)
<0){
18regerror(err,®,errbuf,sizeof(errbuf));
19printf("err:%s\n",errbuf);
20}
21
22err=regexec(®,bematch,nm,pmatch,0);
23
24if(err
2013年06月07日 13点06分 2
有空格没连上什么的
2013年06月07日 14点06分
level 7
偶尔惊悚 楼主
24if(err==REG_NOMATCH){
25printf("no match\n");
26exit(-1);
27}elseif(err){
28regerror(err,®,errbuf,sizeof(errbuf));
29printf("err:%s\n",errbuf);
30exit(-1);
31}
32
33for(inti=0;i<10&&pmatch[i].rm_so!=-1;i++){
34intlen=pmatch[i].rm_eo-pmatch[i].rm_so;
35if(len){
36memset(match,'\0',sizeof(match));
37memcpy(match,bematch+pmatch[i]
.rm_so,len);
38printf("%s\n",match);
39}
40}
41return0
2013年06月07日 13点06分 3
34,41行复制 少空 漏; 
2013年06月07日 13点06分
level 7
偶尔惊悚 楼主
"我们运行得到的结果是
[email protected]
ericchd
com"
2013年06月07日 13点06分 4
level 7
偶尔惊悚 楼主
没有error和warning
2013年06月07日 13点06分 5
1