读配置文件的实现
来源:互联网 发布:数据可视化利器 d3.js 编辑:程序博客网 时间:2024/04/28 03:52
#define SAS3_CONFIGFILE "/mnt/heidun/config/SAS3_Database.conf"
GetStrKeyValue(mysqlusername,"LUserName","RemoteMysql",SAS3_CONFIGFILE);//读配置文件
GetStrKeyValue(mysqlpassword,"LPassWord","RemoteMysql",SAS3_CONFIGFILE);
GetStrKeyValue(mysqldatabaseip,"DataBaseIP","RemoteMysql",SAS3_CONFIGFILE);
GetStrKeyValue(mysqldbname,"mysqlDBName","RemoteMysql",SAS3_CONFIGFILE);
BOOL GetStrKeyValue(LPCTSTR strValue,LPCTSTR strKey,LPCTSTR strSection,LPCTSTR strFileName)
{
FILE *fp;
char buf[STD_BUF];
char *pStart,*pEnd,*index;
if((fp=fopen(strFileName,"r"))==NULL)
{
printf("error happen in open file:%s/n",strFileName);
return FALSE;
}
while(fgets(buf,STD_BUF,fp)!=NULL)
{
index = buf;
while( *(index) == 10 || *(index)== 13 || *(index)== ' ' || *(index)== 9)
index++;
if((*index != '#') && (*index != 0x0a) && (*index != ';') && (index != NULL))
{
pStart = strchr(index,'[');
pEnd = strchr(index,']');
if(pStart!=NULL && pEnd!=NULL)
{
char sSection[50];
memset(sSection,0,50);
memcpy(sSection,pStart+1,pEnd-pStart-1);
if(strcmp(sSection,strSection)==0)
{ //����ҵ�����Ҫ��Section
while(fgets(buf,STD_BUF,fp)!=NULL)
{
while( *(index) == 10 || *(index)== 13 || *(index)== ' ' || *(index)== 9)
index++;
if((*index != '#') && (*index != 0x0a) && (*index != ';') && (index != NULL))
{
pStart = strchr(index,'=');
if(pStart!=NULL)
{
char sKey[50];
memset(sKey,0,50);
memcpy(sKey,index,pStart-index);
if(strcmp(sKey,strKey)==0)
{ //����ҵ�����Ҫ��Key
char sValue[255];
++pStart;
if(*(pStart)=='/'' || *(pStart)=='/"')
{
char *pEnd1,*pEnd2;
pStart++;
pEnd1 = strchr(pStart,'/'');
pEnd2 = strchr(pStart,'/"');
if(pEnd1!=NULL) *pEnd1 = '/0';
if(pEnd2!=NULL) *pEnd2 = '/0';
}
strcpy(sValue,pStart);
strcpy((char *)strValue,sValue);
fclose(fp);
return TRUE;
}
}
}
}
break;
}
}//end of if("[" "]');
}
}
- 读配置文件的实现
- 使用VC的MFC实现读配置文件
- 使用VC的MFC实现读配置文件
- ini配置文件的代码实现
- scala实现配置文件的合并
- apktool.jar的使用,实现apk反编译读配置文件
- 读配置文件的代码
- 读配置文件的方法
- 读配置文件的代码
- 转载:ini配置文件的代码实现
- VC++操作INI配置文件的实现
- 实现ibatis的动态加载sqlmap配置文件
- Window Mobile配置文件的简单实现
- C#配置文件解析工具的实现
- Struts2配置文件全路径搜索的实现
- 实现ibatis的动态加载sqlmap配置文件 .
- 黑马程序员_java 配置文件RunTime的实现
- 用反射+配置文件实现数据库的访问
- How to use VC++6.0 to develop web Service Client
- poi 处理excel文件时的问题,及解决方案
- 软件项目经理所必需具备的素质
- 使用sql2005的分页语句
- Ogre 地形管理
- 读配置文件的实现
- SQL进行排序、分组、统计技巧
- Rob Hess的SIFT算法的C语言实现(基于OpenCV)(调通!!!)
- ww
- 由fork()和vfork()回忆下OS的内存管理
- spring 2.5 annotations配置ehcache
- 为迎接南京大学2012年110周年校庆 在京校友名录重编工作开始了
- ubuntu快捷键设置
- hudson渗透经验