fork download
  1. #include <regex.h>
  2. #include <stdio.h>
  3.  
  4. int validate_var(char *str)
  5. {
  6. regex_t reg;
  7. printf("error code %d\n" ,regcomp(&reg, "^[a-zA-Z]+[a-zA-Z0-9]*$", 0));
  8. int r = regexec(&reg, str, 0, NULL, 0);
  9. regfree(&reg);
  10.  
  11. return r;
  12. }
  13.  
  14. int main() {
  15. printf("%d\n", validate_var("abc")); // Reports 1, This makes sense
  16. printf("%d\n", validate_var("17")); // Reports 1, This doesn't make sense
  17. }
Runtime error #stdin #stdout 0s 2140KB
stdin
Standard input is empty
stdout
error code 0
1
error code 0
1