部分GNU代码片 2、read_configfile

//读取配置文件的内容


//获取配置文件的参数信息
bool read_configfile(
        char* configfile, stCFG &ostCFG)
{
    FILE* f;
    char line[256];
   
    char* p=(char*)NULL;
   
    int iFinish = 0;
    if ((f = fopen(configfile, "r")) == (FILE*)NULL)
    {
        printf("can not open  file %s  ", configfile);
        return false;
    }
   
    while (fgets(line, 256, f)!=(char*)NULL)
    {
        if (line[0]=='#')
            continue;
       
        if ((p = strstr(line, "username")))
        {
            trim_whitespace(line);
            strcpy(ostCFG.mysql_username, line+strlen("username"));
            trim_whitespace(ostCFG.mysql_username);
            iFinish++;
        }
        else if ((p = strstr(line, "password")))
        {
            trim_whitespace(line);
            strcpy(ostCFG.mysql_password, line+strlen("password"));
            trim_whitespace(ostCFG.mysql_password);
            iFinish++;
        }
       
        else if ((p = strstr(line, "dbname")))
        {
            trim_whitespace(line);
            strcpy(ostCFG.mysql_dbname, line+strlen("dbname"));
            trim_whitespace(ostCFG.mysql_dbname);
            iFinish++;
        }
       
    }
    fclose(f);
    //配置文件是不是正确得到了配置
    if (NUM_PARA_IN_CFG != iFinish)
    {
        return false;
    }
    return true;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值