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(&regex,"^\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(&regex, c, (size_t) 0, null, 0);  refree(&regex);  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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -