Its not a script, it is a single function called match() You pass match two arguments - one is the string you want to check, the other the regex patern you want that string to match. The regex pattern is shown in the Perl example. The function returns 1 if it matches. I don't know how it could be simpler.

[root@devel3 root]# cat test.c #include <stdio.h> #include <regex.h> int main(int argc, char *argv[]) { int i; char *pat = "^[A-Z]+$"; printf("Got %d args\n", argc-1 ); /* first arg prog name */ for( i=1; i<argc; i++ ) { printf("Got %s\n",argv[i]); if ( match( argv[i], pat ) ) { printf("-->Match %s\n", pat); } else { printf("***Fail\n"); } } return 0; } int match(const char *string, char *pattern) { int status; regex_t re; if (regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) { return(0); /* report error */ } status = regexec(&re, string, (size_t) 0, NULL, 0); regfree(&re); if (status != 0) { return(0); /* report error */ } return(1); } [root@devel3 root]# gcc test.c [root@devel3 root]# ./a.out 123 ABC abc ABC123 Got 4 args Got 123 ***Fail Got ABC -->Match ^[A-Z]+$ Got abc ***Fail Got ABC123 ***Fail [root@devel3 root]#

I have no comprehension why you want to do data validation in C before you call a Perl script. Surely the Perl does data validation????? If so just use your C wrapper to exec the Perl script. End of story.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: Re: passing c agruments to Perl by tachyon
in thread passing c agruments to Perl by koryw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.