delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/10/24/10:20:31

Date: Thu, 24 Oct 2002 07:20:25 -0700
Mime-Version: 1.0 (Apple Message framework v546)
Subject: POSIX REGEX
From: Daniel Staudigel <dstaudi AT san DOT rr DOT com>
To: djgpp AT delorie DOT com
Message-Id: <BD3EB335-E75B-11D6-A767-000A277B4E20@san.rr.com>
X-Mailer: Apple Mail (2.546)
Reply-To: djgpp AT delorie DOT com

--Apple-Mail-4--820032763
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

The tutorial on your site is great, but I think some sample code would
be in order.  I think that my code *should* work, but when I printf, it
comes up blank, sorry to sound like a n00b, but in C regex, I sure as
heck am.

#include <stdio.h>
#include <sys/types.h>
#include <regex.h>

int main (int argc, const char * argv[]) {

      regex_t regex;
      regmatch_t matches[4];

      char string[] = "uhohthismaynotwork";

      regcomp(&regex,"uhoh\([[:alnum:]]\)",0);
      regexec(&regex,string,4,matches,0);

      printf("%s - %s\n",string,string+matches[0].rm_so);

      return 0;
}

and I get:

CREGEX has exited due to signal 11 (SIGSEGV).

during the printf statement.  rm_so is obviously out of bounds, but I
don't have a clue why that would be.

Thanks a lot.

Daniel Staudigel

--Apple-Mail-4--820032763
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
	charset=US-ASCII

The tutorial on your site is great, but I think some sample code would

be in order.  I think that my code *should* work, but when I printf, it

comes up blank, sorry to sound like a n00b, but in C regex, I sure as

heck am.


#include <<stdio.h>

#include <<sys/types.h>

#include <<regex.h>


int main (int argc, const char * argv[]) {


     regex_t regex;

     regmatch_t matches[4];


     char string[] = "uhohthismaynotwork";


     regcomp(&regex,"uhoh\([[:alnum:]]\)",0);

     regexec(&regex,string,4,matches,0);


     printf("%s - %s\n",string,string+matches[0].rm_so);


     return 0;

}


and I get:


CREGEX has exited due to signal 11 (SIGSEGV).


during the printf statement.  rm_so is obviously out of bounds, but I

don't have a clue why that would be.


Thanks a lot.


Daniel Staudigel


--Apple-Mail-4--820032763--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019