通用C语言函数:文本文件有关操作,.CFG/.INI类配置文件读写。我们知道WINDOWS下的软件可以使用.INI文件
处理程序配置,那么在DOS、UNIX、AS/400上又如何才能读写.CFG/.INI类配置文件? 你可以使用本程序的有关函
数很方便地实现。注:AS/400上输入和显示[]有些问题,所以用{}代替来将section名括起。
GCFTXTF.C -- General C functions for Text File Read/Write
M.L.Y 2000.1.1
MODIFIED (YYYY.MM.DD)
M.L.Y 2000.01.01 - Creation
*/
#if __OS400__ /* AS/400 */
#include "GCFTXTFH"
#else
# include "GCFTXTF.H"
#endif
struct txt_line_flds txt_line_fld[MAX_TXT_LINE_FLD];
char CFG_ssl = '[', CFG_ssr = ']'; /* .CFG/.INI file section symbol */
int CFG_section_line_no, CFG_key_line_no, CFG_key_lines;
/* ------------------------------------------------------------------------- */
int fgetline(FILE *fp, USGC *buffer, int maxlen)
/*
Read 1 line text into *buffer from file *fp, return length actually read.
maxlen --- max. length of *buffer
CR or LF is not put into *buffer
FF(0x0C) is put into *buffer and then return
Ctrl-Z(0x1A) is put into *buffer and then return
If EOF was detected then return -1
If an error occurred then return -2
M.L.Y 1995.06.09, 07.31, 1998.9.9
*/
{
#if __OS400__ /* AS/400 */
int i;
memset(buffer, 0x00, maxlen);
if(fgets(buffer, maxlen, fp) == NULL)
{
i = strlen(buffer);
if(feof(fp) != 0)
{
if(i == 0) return -1; /* EOF */
}
else return -2; /* error */
| 论坛热门帖子: | [lch203] 写得蛮好的linux学习笔记(10-21) [黑马制造] 学习java的30个目标(10-19) [笑傲股林] 做测试半年了,有点迷茫,应该再学些什么提高自己的测试水平和测试能力呢?(10-19) [udp8589] 大家用google的来吱一声? 用百度的~~也来报道下?(10-18) [沂偌掳兆] 本人总结的一些认为C++比较经典的书籍,希望对大家有用(10-18) |
| TAG标签: | 文件 操作 配置 有关 源码 语言 函数 文本 通用 if buf1 |
注册
个人空间
