#include
#include
#include
/**
*Fetch all numbers & word
*gcc 005.c -o 005.app `pkg-config --cflags --libs glib-2.0`
*/
int match(char* line,char* pattern);
int main(int argc,char** argv){
FILE* fp = fopen("./005.c","r");
if(fp == NULL){
g_print("%s\n",strerror(errno));
return -1;
}
char line[1024];
int line_no = 0;
while(fgets(line,1024,fp)){
match(line,"[0-9]+");
match(line,"[A-Za-z]+");
}
fclose(fp);
return 0;
}
int match(char* line,char* pattern){
GRegex* regex = NULL;
GMatchInfo* match_info = NULL;
regex = g_regex_new(pattern,0,0,NULL);
g_regex_match(regex,line,0,&match_info);
while(g_match_info_matches(match_info)){
gchar* word = g_match_info_fetch(match_info,0);
if(word)
g_print("%s\n",word);
g_free(word);
g_match_info_next(match_info,NULL);
}
g_match_info_free(match_info);
g_regex_unref(regex);
}
阅读(928) | 评论(0) | 转发(0) |