Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <regex.h>
- #define size 1024
- int main(int argc, char **argv){
- FILE *fp;
- char line[size];
- regex_t re[33];
- int x;
- const char *filename = "enwik8";
- const char *strings[] = {"\bhome\b", "\bdear\b", "\bhouse\b", "\bdog\b", "\bcat\b", "\bblue\b", "\bred\b", "\bgreen\b", "\bbox\b", "\bwoman\b", "\bman\b", "\bwomen\b", "\bfull\b", "\bempty\b", "\bleft\b", "\bright\b", "\btop\b", "\bhelp\b", "\bneed\b", "\bwrite\b", "\bread\b", "\btalk\b", "\bgo\b", "\bstay\b", "\bupper\b", "\blower\b", "\bI\b", "\byou\b", "\bhe\b", "\bshe\b", "\bwe\b", "\bthey\b"};
- for(x = 0; x < 33; x++){
- if(regcomp(&re[x], strings[x], REG_EXTENDED) != 0){
- printf("Failed to compile regex '%s'\n", strings[x]);
- return -1;
- }
- }
- fp = fopen(filename, "r");
- if(fp == 0){
- printf("Failed to open file %s\n", filename);
- return -1;
- }
- while((fgets(line, size, fp)) != NULL){
- for(x = 0; x < 33; x++){
- regexec(&re[x], line, 0, NULL, 0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement