WritePrivateProfileString(m_szUserPath, "FEATURELEN", cOffset, m_cConfigDir);Linux写法
时间: 2023-11-27 18:50:24 浏览: 44
在 Linux 中,可以使用配置文件库(如libconfig或libini)来读写INI文件。这里提供一个使用libini的示例:
```
#include <stdio.h>
#include <stdlib.h>
#include <libini.h>
int main() {
char *user_path = "/path/to/user.ini";
char *feature_len_key = "FEATURELEN";
char *offset_value = "100";
ini_file_t *ini = ini_file_create();
if (ini_file_load(ini, user_path) != INI_SUCCESS) {
printf("Failed to load ini file %s\n", user_path);
return -1;
}
ini_section_t *section = ini_find_section(ini, "");
if (section == NULL) {
section = ini_section_create("");
ini_add_section(ini, section);
}
ini_property_t *property = ini_find_property(section, feature_len_key);
if (property == NULL) {
property = ini_property_create(feature_len_key, offset_value);
ini_add_property(section, property);
} else {
ini_property_set_value(property, offset_value);
}
if (ini_file_save(ini, user_path) != INI_SUCCESS) {
printf("Failed to save ini file %s\n", user_path);
return -1;
}
ini_file_destroy(ini);
return 0;
}
```
注意,这里使用了libini库来读写INI文件。可以使用包管理器来安装此库。例如,在Ubuntu上使用以下命令安装:
```
sudo apt-get install libini-config-dev
```