[ 永远的UNIX::UNIX技术资料的宝库 ]

首页 > 编程技术 > 源码天堂 > 正文
C源码:.CFG/.INI配置文件读写测试程序
本文出自:http://mly363.363.net 作者: (2001-08-19 13:05:00)
/* CFG-TEST.C --- Test .CFG/.INI file read/write
   (C) M.L.Y  2000.12
*/

#if __OS400__                /* AS/400 */
  #include "GCFTXTFC"
  #include "GCFSTRC"
#else
# include "GCFTXTF.C"
# include "GCFSTR.C"
#endif

main()
{
  USGC cfg_file[255], section[255], key[255], val[1024];
  char get_set[255], yn[255];
  int  rc;

  printf("CFG-TEST --- Test .CFG/.INI file read/write\n");
  printf("(C) M.L.Y  2000.12\n\n");
  printf("Please input .INI/.CFG file name:");
  gets((char *)cfg_file);
  while(1)
  {
    printf("get/set(G/S)?");
    gets(get_set);
    ltrimstr(rtrimstr(get_set));
    if(get_set[0] == 'g' || get_set[0] == 'G' ||
       get_set[0] == 's' || get_set[0] == 'S')
      break;
  }
  printf("Please input section name:");
  gets((char *)section);
  printf("Please input key name:");
  gets((char *)key);
  if(get_set[0] == 's' || get_set[0] == 'S')
  {
    printf("Please input key value:");
    gets((char *)val);
  }
  printf("\nFilename='%s', operation='%c',\n", cfg_file, get_set[0]);
  printf("section=[%s], key='%s'\n", section, key);
  if(get_set[0] == 's' || get_set[0] == 'S')
    printf("key value='%s'\n", val);
  printf("Are you sure(Y/N)?");
  gets(yn);
  ltrimstr(rtrimstr(yn));
  if(yn[0] != 'y' && yn[0] != 'Y') return 0;
  if(get_set[0] == 's' || get_set[0] == 'S')
    rc = CFG_set_key(cfg_file, section, key, val);
  else
  {
    rc = CFG_get_key(cfg_file, section, key, val);
    if(rc == 0)
      printf("Key value='%s'\n", val);
  }
  printf("Return code = %d\n", rc);
  return rc;
}

/* End of file */
(http://www.fanqiang.com)
    进入【UNIX论坛

相关文章
C源码:通用C语言函数:文本文件有关操作,.CFG/.INI类配置文件读写(对应.C的头文件 ) (2001-08-19 09:05:00)
C源码:通用C语言函数:文本文件有关操作,.CFG/.INI类配置文件读写 (2001-08-19 08:05:00)
 

★  樊强制作 欢迎分享  ★