regex - C regular expressions, regcomp -
i'm trying make way around regular expressions check if string integer. figured pattern should ^\d$
, wrote function print error if argument not fit:
regex_t regex; void check_int(char *c) { check=regcomp(®ex,"^\d$",0); if (check!=0) { perror("4th element on line not integer!"); exit(5); } else printf("4th arg number."); }
i'm not sure how regcomp
works, used thought should after checking examples on internet. trouble says string number, can't figure out why...
added this, returns no match:
status = regexec(®ex, c, (size_t) 0, null, 0); refree(®ex); if(status!=0) { perror(".."); exit(5); }
regcomp
used compile regular expression pattern, not match against input string. match against string, need use regexec
. in case, return value of regcomp
0 because pattern seems compiled without error.
see this link synopsis each of different functions , usage examples.
Comments
Post a Comment