30.过滤掉smb.conf配置文件中的空行和注释行和空白行(初级写法很不严谨)

 1 #define F_PRINT_ERR(e)
 2 do
 3 {
 4     if(e == NULL)
 5     {
 6       printf("open error");
 7       exit(-1);
 8     }
 9 }
10 while(0)
11 int main(void)
12 {
13     FILE *pf = fopen("G:/qtcode/smb.conf","r+");
14     F_PRINT_ERR(pf);
15 
16     char buf[1024];//配置文件有个不成文的1024规定
17 
18     FILE* pfbak = fopen("G:/qtcode/smb.conf.bak","w+");
19 
20     if(NULL == pfbak)
21     {
22         fclose(pf);
23         exit(-1);
24     }
25 
26     while(fgets(buf,1024,pf))
27     {
28         //去注释行,去空行,去空白行(不过这里的空白行只是简单的空格/制表符+
而已)
29         //如果有些有效行前面有空白,那么就不能这样写了!
30         if(*buf == '#' || *buf == '
' || *buf == ' ' || *buf == '	')
31         {
32             continue;
33         }
34         printf("%s",buf);
35         fputs(buf,pfbak);
36     }
37 
38     fclose(pf);
39     fclose(pfbak);
40 
41 
42     return 0;
43 }
原文地址:https://www.cnblogs.com/ZhuLuoJiGongYuan/p/9480738.html