Re: c regex example
- From: Ico <usenet@xxxxxxx>
- Date: 21 Jul 2007 07:21:17 GMT
gert <gert.cuykens@xxxxxxxxx> wrote:
Can anybody tell whats wrong ?
You forgot to check the return value of the regcomp() call:
"regcomp() returns zero for a successful compilation or an error code
for failure."
#include <stdio.h>
#include <string.h>
#include <regex.h>
void
csv(char *buffer)
{
char *line;
char *errbuf;
size_t errbuf_size;
int errcode;
regex_t re;
regmatch_t rm;
regcomp (&re, ",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))",
Save the return value of regcomp() and use regerror() to convert the
error code into a readable string when not zero
REG_EXTENDED);
errcode=regexec(&re, &buffer[0], 1, &rm, 0);
while(errcode==0)
{
strncpy (line, buffer+rm.rm_so, rm.rm_eo-rm.rm_so);
printf("%s\n",line);
errcode=regexec (&re, buffer+rm.rm_eo, 1, &rm, 0);
}
regerror(errcode,&re,errbuf,errbuf_size);
printf("%s\n",errbuf);
regfree(&re);
}
int
main(void)
{
csv("test,test");
}
--
:wq
^X^Cy^K^X^C^C^C^C
.
- Follow-Ups:
- Re: c regex example
- From: gert
- Re: c regex example
- References:
- c regex example
- From: gert
- c regex example
- Prev by Date: c regex example
- Next by Date: Free test papers of companies,GRE,GMAT
- Previous by thread: c regex example
- Next by thread: Re: c regex example
- Index(es):