/*
* ini.c
*
* Created on: 2021年3月2日
* Author: ubuntu
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sysdefines.h"
#define SECTION_MAX_LEN 256
#define STRVALUE_MAX_LEN 256
#define LINE_CONTENT_MAX_LEN 256
//read value from .ini
void IniReadValue(char* section, char* key, char* val, const char* file)
{
FILE* fp;
int i = 0;
int lineContentLen = 0;
int position = 0;
char lineContent[LINE_CONTENT_MAX_LEN];
char bFoundSection = 0;
char bFoundKey = 0;
fp = fopen(file, "r");
if(fp == NULL)
{
printf("%s: Opent file %s failed.\n", __FILE__, file);
return;
}
while(feof(fp) == 0)
{
memset(lineContent, 0, LINE_CONTENT_MAX_LEN);
fgets(lineContent, LINE_CONTENT_MAX_LEN, fp);
if((lineContent[0] == ';') || (lineContent[0] == '\0') || (lineContent[0] == '\r') || (lineContent[0] == '\n'))
{
continue;
}
//check section
if(strncmp(lineContent, section, strlen(section)) == 0)
{
bFoundSection = 1;
//printf("Found section = %s\n", lineContent);
while(feof(fp) == 0)
{
STM32系列单片机读取配置文件
于 2021-10-24 15:02:00 首次发布