Mega Code Archive

 
Categories / C / Development
 

Print all urls found in text file

#include <stdio.h> #include <regex.h> #include <stdlib.h> #include <string.h> #include <locale.h> #include <sys/types.h> int main(void) { char line[1024]; char delim[] = "<> \t\n"; char *word = NULL; int retval = 0; regex_t re; setlocale(LC_ALL, ""); if(regcomp(&re, "href", REG_ICASE) != 0) return 1; while((fgets(line, 1024, stdin)) != NULL) { word = strtok(line, delim); while(word != NULL) { if((retval = regexec(&re, word, 0, NULL, 0)) == 0) printf("%s\n", word); word = strtok(NULL, delim); } } return 0; }