请教linux(C语言)下标准ini文件的读取,写入?配置管理

xuexic 2009-02-09 10:46:21
各位大师:

windows下ini文件的标准格式及配置管理搞定(采用了WINDOWS API函数),

现在程序要移植到linux平台上,请教各位:

那linux下(C语言)如何对ini文件进行读取,写入??

谢谢!
...全文
663 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hotsnow1943 2009-02-09
  • 打赏
  • 举报
回复

GTK 2.0 编程范例
这本书里第八章有介绍ini配置文件的生成\读写的内容
可以去看看

书有很多地方可以下,CSDN就有

至少可以照着写,应该可以解决问题
joyself 2009-02-09
  • 打赏
  • 举报
回复
c语言本身没有现成的,不过你可以参考linux的一些开源软件,看看别人如何写的
ewuby 2009-02-09
  • 打赏
  • 举报
回复
c讲究的就是灵活,配置文件的读写完全可以自己写个类去实现
快乐田伯光 2009-02-09
  • 打赏
  • 举报
回复
一样的操作文件就是了啊,open, read, write
chenzhixin 2009-02-09
  • 打赏
  • 举报
回复
/************************************************************************
T h e O p e n W i n d o w s P r o j e c t
------------------------------------------------------------------------
Filename : IniFile.h
Author(s) : Carsten Breuer
------------------------------------------------------------------------
Copyright (c) 2000 by Carsten Breuer (C.Breuer@openwin.de)
************************************************************************/

#ifndef __INIFILE_H__
#define __INIFILE_H__

//#ifdef LINUX /* Remove CR, on unix systems. */
#define INI_REMOVE_CR
#define DONT_HAVE_STRUPR
//#endif

#define tpNULL 0
#define tpSECTION 1
#define tpKEYVALUE 2
#define tpCOMMENT 3

struct ENTRY{
char Type;
char *Text;
struct ENTRY *pPrev;
struct ENTRY *pNext;
};

struct ENTRY ENTRY;

typedef struct{
struct ENTRY *pSec;
struct ENTRY *pKey;
char KeyText[128];
char ValText[128];
char Comment[255];
}EFIND;

/* Macros */
#define ArePtrValid(Sec,Key,Val) ((Sec!=NULL)&&(Key!=NULL)&&(Val!=NULL))

/* Connectors of this file (Prototypes) */

char OpenIniFile (const char *FileName);

char Readchar (const char *Section, const char *Key, char Default);
int ReadInt (const char *Section, const char *Key, int Default);
double ReadDouble (const char *Section, const char *Key, double Default);
const char *ReadString (const char *Section, const char *Key, const char *Default);

void Writechar (const char *Section, const char *Key, char Value);
void WriteInt (const char *Section, const char *Key, int Value);
void WriteDouble (const char *Section, const char *Key, double Value);
void WriteString (const char *Section, const char *Key, const char *Value);

char DeleteKey (const char *Section, const char *Key);
char DeleteSection(const char *Section);//FIXME:这是我加的

void CloseIniFile ();
char WriteIniFile (const char *FileName);

#endif /*__INIFILE_H__*/



你在GOOGLE CODE中搜索这个文件就可以了。
记得使用字符串操作的时候,返回字符串需要strcpy下,因为返回的是个全局变量,后边还会被使用掉

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧