尧图建网站 尧图建网站 YAOTU WEB BUILD 免费咨询
ARTICLE DETAIL

资讯详情

深耕网站建设与建站编程的一线实战洞察。

读取文件里,某个属性赋值情况_bak2

读取文件里,某个属性赋值情况_bak2 读取文件里某个属性赋值情况_bak2int read_config_int(const char *file, const char *key, int default_value) { FILE *fp fopen(file, r); if (!fp) { printf(Failed to open %s\n, file); return default_value; } char line[256]; while (fgets(line, sizeof(line), fp)) { /* 去掉换行 */ line[strcspn(line, \r\n)] \0; /* 跳过空行 */ char *p line; while (*p isspace((unsigned char)*p)) p; if (*p \0) continue; /* 跳过注释 */ if (*p # || *p ;) continue; /* 判断key是否匹配 */ int key_len strlen(key); if (strncasecmp(p, key, key_len) 0) { p key_len; while (*p isspace((unsigned char)*p)) p; if (*p ! ) continue; p; while (*p isspace((unsigned char)*p)) p; fclose(fp); return atoi(p); } } fclose(fp); return default_value; } // 调用示例 int log read_config_int(/system/t.ini, log, -1); int camera_num read_config_int(/system/t.ini, camera_num, 0); int enable read_config_int(/system/t.ini, enable, 0);
返回列表