⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 读写ini文件.txt

📁 参照网上的例子改写的多叉树的读写程序
💻 TXT
字号:
/* 
 * File: inifile.h 
 * Read INI File 
*/ 
#ifndef _INIFILE_H_ 
#define _INIFILE_H_ 

#include <stdio.h> 
#include <string.h> 

/* 
 * char* GetInitKey(FileName, Section, Key) 
 * Return Key=>Value 
 * Ex: 
 * 
 * + [config] 
 * + dbhost=localhost 
 * 
 * strcpy(dbhost,GetInitKey("config.ini", "config", "dbhost")); 
*/ 
char * GetInitKey(char *filename, char *title,char *key) 
{ 
   FILE * fp; 
   char tmpLine[1024]; 
   int rtnval; 
   int i = 0; 
   int flag = 0; 
   char * tmp; 
   static char tmpstr[1024]; 
    
   if ((fp = fopen( filename, "r")) == NULL ) 
   { 
      return "have no such file"; 
   } 
   while (!feof(fp)) 
   { 
      rtnval = fgetc( fp ); 
      if ( rtnval == EOF ) 
      { 
         break; 
      } 
      else 
      { 
         tmpLine[i++] = rtnval; 
      } 
      if ( rtnval == '\n' ) 
      { 
         tmpLine[--i]=0; 
         i = 0; 
         tmp = strchr(tmpLine, '='); 
          
         if (( tmp != NULL )&&(flag == 1)) 
         { 
            if (strstr(tmpLine,key)!=NULL) 
            { 
               strcpy ( tmpstr, tmp + 1 ); 
               fclose ( fp ); 
                
               return tmpstr; 
            } 
         } 
         else 
         { 
            strcpy(tmpstr,"["); 
            strcat(tmpstr,title); 
            strcat(tmpstr,"]"); 
            if (strcmp(tmpstr,tmpLine)==0) 
            { 
               flag = 1; 
            } 
         } 
       
      } 
   } 
   fclose ( fp ); 
   return ""; 
} 

#endif //_INIFILE_H_ 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -