sc/ini/ini_example.c

52 lines
1.1 KiB
C
Raw Normal View History

2020-11-11 01:19:49 +03:00
#include "sc_ini.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
const char *example_ini = "# My configuration"
"[Network] \n"
"hostname = github.com \n"
"port = 443 \n"
"protocol = https \n"
"repo = any";
int callback(void *arg, int line, const char *section, const char *key,
2020-11-11 01:19:49 +03:00
const char *value)
{
printf("Line : %d, Section : %s, Key : %s, Value : %s \n", line, section,
key, value);
return 0;
}
void file_example(void)
{
int rc;
FILE *fp = fopen("my_config.ini", "w+");
fwrite(example_ini, 1, strlen(example_ini), fp);
fclose(fp);
printf(" \n Parse file \n");
rc = sc_ini_parse_file(NULL, callback, "my_config.ini");
assert(rc == 0);
}
void string_example(void)
{
int rc;
printf(" \n Parse string \n");
rc = sc_ini_parse_string(NULL, callback, example_ini);
assert(rc == 0);
}
int main(int argc, char *argv[])
{
string_example();
file_example();
}