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)
|
|