[ create a new paste ] login | about

Link: http://codepad.org/t4ZYxS5l    [ raw code | output | fork ]

appunti2 - C, pasted on May 1:
#include <stdio.h>
#include <regex.h>

int
regex_match (char *pattern, const char *string)
{
    int       status;
    regex_t   re;
    status = regcomp (&re, pattern, REG_EXTENDED|REG_NOSUB);
    if (status != 0)
      {
        return (0);
      }
    status = regexec (&re, string, (size_t) 0, NULL, 0);
    if (status != 0)
      {
        regfree (&re);
        return (0);
      }
    regfree (&re);
    return (1);
}

int
main (void)
{
    char *string       = "Ciao amore mio";
    char *re           = "iao";

    if (regex_match (re, string))
      {
        printf ("Il modello \"%s\" trova corrispondenza ",
                re);
        printf ("nella stringa \"%s\"\n", string);
      }
    else
      {
        printf ("Il modello \"%s\" ", re);
        printf ("NON trova corrispondenza ");
        printf ("nella stringa \"%s\"\n", string);
      }
    return 0;
}


Output:
1
Il modello "iao" trova corrispondenza nella stringa "Ciao amore mio"


Create a new paste based on this one


Comments: