#include
#include
#include
/**
*Print line no. of empty line
*gcc 004.c -o 004.app `pkg-config --cflags --libs glib-2.0`
*/
int main(int argc,char** argv){
GRegex* regex = NULL;
GMatchInfo* match_info = NULL;
FILE* fp = fopen("./004.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)){
line_no++;
regex = g_regex_new("^$",0,0,NULL);
g_regex_match(regex,line,0,&match_info);
while(g_match_info_matches(match_info)){
g_match_info_next(match_info,NULL);
g_print("%d:%s\n",line_no,"This is a blank line");
}
g_match_info_free(match_info);
g_regex_unref(regex);
}
fclose(fp);
return 0;
}
阅读(923) | 评论(0) | 转发(0) |