|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
<al.moorthi@gmail.com> wrote in message > int num_matches; > > success = regexec(&test_reg, cool, num_matches, matches, 0); > Looks suspicious to me. Surely you should pass &num_matches so that regexec() can fill in the answer? I don't know the prototype for regexec(), so this may be wrong. -- Free games and programming goodies. http://www.personal.leeds.ac.uk/~bgy1mm |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
al.moorthi@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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Malcolm McLean wrote:
> > <al.moorthi@gmail.com> wrote in message >> int num_matches; make this "int num_matches = 3;" or (better) "size_t num_matches = 3;" >> >> success = regexec(&test_reg, cool, num_matches, matches, 0); >> > Looks suspicious to me. Surely you should pass &num_matches so that > regexec() can fill in the answer? > I don't know the prototype for regexec(), so this may be wrong. Malcolm's instincts are right. num_matches needs to be initialized to indicate how many matches you can handle (loosely speaking). |
|
![]() |
| Outils de la discussion | |
|
|