468,504 Members | 1,985 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,504 developers. It's quick & easy.

regexec from regex.h Segmentation fault

the below program is working in Suse and not working on Cent 5:
can any body have the solution ?

#include <regex.h>
#include <stdlib.h>
#include <stdio.h>

int main(){

char cool[] = "http://www.cnn.com:80/wowsers.html";
regex_t test_reg;
regmatch_t matches[3];
int num_matches;
int success = regcomp(&test_reg, "http://([^/]*)(/{0,1}.*)",
REG_EXTENDED | REG_ICASE);
printf("regcomp success = %d\r\n", success);
success = regexec(&test_reg, cool, num_matches, matches, 0);
printf("regexec success = %d\r\n", success);
printf("overall match start index = %d\r\n", matches[0].rm_so);
printf("overall match end index = %d\r\n",
matches[0].rm_eo);
printf("first match start index = %d\r\n", matches[1].rm_so);
printf("first match end index = %d\r\n", matches[1].rm_eo);
printf("second match start index = %d\r\n", matches[2].rm_so);
printf("second match end index = %d\r\n", matches[2].rm_eo);

}

OUTPUT on SuSE(10.2):
../regex
regcomp success = 0
regexec success = 0
overall match start index = 0
overall match end index = 34
first match start index = 7
first match end index = 21
second match start index = 21
second match end index = 34
OUTPUT on Cent(5):
../regex
regcomp success = 0
Segmentation fault

MORE DETAILS:
regex.h are same on both machine.

ldd ./regex ( on Cent 5 )
linux-gate.so.1 = (0x00a43000)
libc.so.6 =/lib/libc.so.6 (0x00110000)
/lib/ld-linux.so.2 (0x0093c000)
glibc-devel-2.5-12 (rpm -qf /usr/include/regex.h)
ldd ./regex ( on SuSE 10.2 )
linux-gate.so.1 = (0xffffe000)
libc.so.6 =/lib/libc.so.6 (0xb7d8c000)
/lib/ld-linux.so.2 (0xb7ee9000)
glibc-devel-2.5-25 (rpm -qf /usr/include/regex.h)
Feb 4 '08 #1
1 4838
al********@gmail.com writes:
the below program is working in Suse and not working on Cent 5:
can any body have the solution ?

#include <regex.h>
#include <stdlib.h>
#include <stdio.h>

int main(){

char cool[] = "http://www.cnn.com:80/wowsers.html";
regex_t test_reg;
regmatch_t matches[3];
int num_matches;
int num_matches = 3;

You are expected to say how big the matches array is. This is not
really on-topic here. Further problem should go to
comp.unix.programmer since this is a POSIX interface.

--
Ben.
Feb 4 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Fra-it | last post: by
18 posts views Thread by Digital Puer | last post: by
27 posts views Thread by Paminu | last post: by
7 posts views Thread by pycraze | last post: by
3 posts views Thread by madunix | last post: by
6 posts views Thread by DanielJohnson | last post: by
2 posts views Thread by apoorva.groups | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.