C语言版的DBF本地数据库文件操作函数

本文分享了一套1991年编写的DBF文件操作C语言库,包括文件的创建、打开、读取、写入、复制等功能,并提供了详细的源代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

几个月前,翻出以前的一些1993 - 1995年的C/C++老代码,陆续粘贴到了BLOG上,一来以免不小心遗失(以前很多好代码都丢了),二来可供C/C++爱好者,特别是初学者借鉴参考,本以为就这些了,没料到月头又找出一些更老的代码,都是1991年及以前的,前几天我发上来的《C语言版的磁盘文件分片归并排序函数》就是其中之一。今天准备把1991年用TURBOC 2.0写的DBF本地数据库文件操作函数完整的贴在这里,前几个月发的文章《C++老代码 -- DBF数据文件操作类DBFile》应该是我当时从C向C++过渡时根据这里的C代码改写的。

其实还有个通用的用B+树建立本地数据索引文件的工具代码,本想在《C语言版的磁盘文件分片归并排序函数》之后贴上来,但是由于目前32位计算机与以前的16位计算机的数据类型长度不一样,而索引文件是分索引节点块写道磁盘文件上的,数据类型长度不同必定引起移植错误(以前没想这么多 ^_^ ),再看到《C语言版的磁盘文件分片归并排序函数》很受朋友们捧场(一天的电击量达到了1000多),错误多了会挨骂的,所以,只能等春节后找几天时间改一下(代码很长很复杂的)后再贴出来。顺便在此感谢大家的捧场,也感谢优快云编辑把文章挂在了首页,才能让这么多的朋友光临。

需要说明的是,1991年我正好业余学习计算机语言2年多时间,其中包括学习BASIC、PASCAL及汇编等,所以C语言可能掌握的不大好,更谈不上代码设计,加上我又不懂英语,标识符命名也不规范等,因此有什么不对的地方可以写信给我(maozefa@hotmail.com),也可留言,但是代码在16位机上绝对是可行的,记得我以前经常用的,但是要用到32位机上,和DBF文件有关的几个结构的数据类型要改一下,很简单的,只是把int变为short就行了的(好像就2处地方),我自己没改是因为该代码与2个通用排序函数不一样,目前实用价值不大,就让它保持原样吧!

下面是代码,没写测试程序:

/*
*********************DBASE数据文件操作C库文件************************
*文件名:MDBFIO.H*
*编制人:湖北省公安县统计局毛泽发*
*日期:1991.8*
***************************************************************************
*/
#include
< stdio.h >

#define MAXFILES10
#define MAXFIELD128/*......记录最大字段数*/
#define MAXNAMES11/*......字段名最大长度*/
#define MAXFIESIZE254/*......字符字段最大位数*/
#define MAXWIDTH19/*......数据字段最大位数*/
#define MAXDEC15/*......数据小数最大位数*/
#define DBFFILE3/*......头结构开始标记*/
#define DBFSTREND0x000d/*......头结构结束标记*/
#define DBFEND26/*......文件结束标记*/
#define DELFLAG'*'/*记录删除标记*/
#define TOP0l/*首记录标志*/
#define BOTTOM-1/*末记录标志*/
#define SPACE32

/* 内部字段信息结构 */
typedef
struct dbfield{
char name[MAXNAMES]; /* 字段名 */
char type; /* 字段类型 */
void far * tech; /* 字段数据地址 */
unsigned
char width,dec; /* 字段长度及小数位 */
char nul[ 14 ]; /* 保留字节 */
}DBFIELD;

/* DBF文件头结构 */
typedef
struct dbfstr{
unsigned
char dbf3; /* DBASE数据文件标记 */
unsigned
char date_n,date_y,date_r; /* 年月日变量 */
unsigned
long record; /* 记录数变量 */
unsigned
int ldb,lrd; /* 头结构.记录长度变量 */
char nul[ 20 ]; /* 头结构保留字节变量 */
}DBFSTR;

/* DBF文件把柄结构 */
typedef
struct dbfile{
FILE
* fdb; /* 文件指针 */
DBFSTRstru;
/* 文件头结构 */
DBFIELD
* start; /* 字段结构首指针 */
char fields; /* 字段数 */
}DBFILE;


/* 外部字段信息结构 */
struct dbf{
char name[MAXNAMES]; /* 字段名变量 */
char type; /* 字段类型变量 */
unsigned
char width,dec; /* 字段长度及小数位变量 */
};
/* db_errorDBASE文件操作出错信息:
0:无错误;1:打开文件过多;2:文件未找到;3:读文件头失败;4:写文件头失败;
5:关闭文件失败;6:打开文件失败;7:移动文件指针出错.
*/
extern unsigned char db_error;

int db_getfields(DBFSTRstr); /* 计算并返回文件字段数 */
void undberror( void ); /* 清除DB_ERROR错误信息 */
int db_getstr(DBFILE * f); /* 读文件头信息,成功返回1,否则0 */
DBFILE
* db_use( char * fname); /* 打开一个已存在文件,返回指针供读写,出错返回NULL */
/* 根据外部字段结构创建一个.DBF文件,成功返回指针供读写,出错返回NULL */
DBFILE
* db_create( char * fname, struct dbf * fd);
/* 关闭一个文件,FLAG=0,不更新文件头,否则更新;成功返回1,否则0 */
int db_close(DBFILE * f, int flag);
/* 写文件头信息,FLAG=0不写字段信息,成功返回1,否则0 */
int db_writestr(DBFILE * f, int flag);
long db_cpyrec(DBFILE * fo,DBFILE * fi, long fosta, long fista, long n, int * fields);
long db_fappend(DBFILE * fo,DBFILE * fi, long starec, long n, int * fields);
int db_copy( char * tofname, char * ffname, int flag, long starec, long n, int * fields);
long db_goto(DBFILE * f, long record);
long db_getrecnum(DBFILE * f);
long db_skip(DBFILE * f, long n);
int db_delete(DBFILE * f, long recs);
int db_recall(DBFILE * f, long recs);
int db_pack( char * fname);
/* **DBFIO.HEND** */

/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_CLOSE.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
< dos.h >
#include
< stdlib.h >
#include
" dbfio.h "
#ifdefTURBOC
#include
< alloc.h >
#else
#include
< malloc.h >
#endif
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_DATE*
*参数:DAT数据文件头结构指针*
*功能:读系统当前时间到头结构中*
*返回值:*
***************************************************************************
*/
void db_date(DBFSTR * dat)
{
char * p,q[ 5 ];
unionREGSinr;
inr.h.ah
= 0x2a ;
intdos(
& inr, & inr);
p
= itoa(inr.x.cx,q, 10 ) + 2 ;
dat
-> date_n = atoi(p);
dat
-> date_y = inr.h.dh;
dat
-> date_r = inr.h.dl;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_CLOSE*
*参数:fDBASE数据文件指针*
*功能:关闭一个DBASE数据文件*
*返回值:成功1,否则0*
***************************************************************************
*/
int db_close(DBFILE * f, int flag)
{
if ( ! f -> fdb) return 0 ; /* 无效文件号 */
if (flag){ /* 如已向文件写数据,更新文件头结构 */
db_date(
& f -> stru);
if ( ! db_writestr(f, 0 )) return 0 ;
}
if (fclose(f -> fdb) == EOF){
db_error
= 5 ;
return 0 ;
}
free(f
-> start);
f
-> fdb = NULL;
return 1 ;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:db_writestr*
*参数:f:DBASE数据文件指针,flag=0不写字段信息,否则整个文件头信息*
*功能:写文件头信息到数据文件*
*返回值:成功1,否则0*
***************************************************************************
*/
int db_writestr(DBFILE * f, int flag)
{
int dbend = DBFSTREND;
if (fseek(f -> fdb, 0l , 0 )) return 0 ;
if ( ! fwrite( & f -> stru, sizeof (DBFSTR), 1 ,f -> fdb)) goto err;
if (flag){
if (fwrite(f -> start, sizeof (DBFIELD),f -> fields,f -> fdb) != f -> fields)
goto err;
if ( ! fwrite( & dbend, sizeof ( int ), 1 ,f -> fdb)) goto err;
}
return 1 ;
err:
db_error
= 4 ;
}
/* **DB_CLOSE.CEND** */

/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_COPY.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
" dbfio.h "
#ifdefTURBOC
#include
< alloc.h >
#else
#include
< malloc.h >
#endif
#include
< string .h >
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_COPY*
*参数:tofname:复制文件名;ffname:被复制文件名;flag:0只复制结构,1包*
*括记录;starec:起始记录(0-N);n:记录数;如n=0,start及以下全*
*部记录;fileds:字段序号表,以-1结尾,如fields=0复制全部字段*
*功能:按条件复制一个文件内容到另一文件中*
*返回值:成功0,被复制文件不存在-1,复制失败-2*
***************************************************************************
*/
int db_copy( char * tofname, char * ffname, int flag, long starec, long n,
int * fields)
{
DBFILE
* fi, * fo, * db_findfile();
register
int i = 0 ,j;
if ((fo = db_findfile()) == NULL) return - 2 ;
if ((fo -> fdb = fopen(tofname, " w+b " )) == NULL){
db_error
= 6 ;
return - 2 ;
}
if ((fi = db_use(ffname)) == NULL) return - 1 ;
memcpy((
char * ) & fo -> stru,( char * ) & fi -> stru, sizeof (DBFSTR));
if ( ! fields){
fo
-> start = fi -> start;
fo
-> fields = fi -> fields;
}
else {
for (;fields[i] >= 0 && fields[i] < fi -> fields && i < MAXFIELD;i ++ );
j
= sizeof (DBFIELD) * i;
if ((fo -> start = (DBFIELD * )malloc(j)) == NULL){
db_close(fi,
0 );
fclose(fo
-> fdb);
fo
-> fdb = NULL;
return - 2 ;
}
memset(fo
-> start, 0 ,j);
fo
-> fields = i;
fo
-> stru.lrd = 0 ;
for (i = 0 ;i < fo -> fields;i ++ ){
j
= fields[i];
memcpy((
char * ) & fo -> start[i],( char * ) & fi -> start[j], sizeof (DBFIELD));
fo
-> stru.lrd += fo -> start[i].width;
}
fo
-> stru.lrd += 1 ;
fo
-> stru.ldb = i * 32 + 34 ;
}
if (flag)db_cpyrec(fo,fi, 0l ,starec,n,fields);
db_close(fi,
0 );
i
= db_writestr(fo, 1 );
if (fields)free(fo -> start);
fclose(fo
-> fdb);
fo
-> fdb = NULL;
if ( ! i){
remove(tofname);
return - 2 ;
}
}
/* **DB_COPY.CEND** */
/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_CPYRE.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
" dbfio.h "
#ifdefTURBOC
#include
< alloc.h >
#else
#include
< malloc.h >
#endif
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_CPYREC*
*参数:fo,fi:分别为复制.被复制文件指针;fosta,fista:分别为fo,fi所指文*
*件起始记录;n:记录数,n=0,包括fista在内以下全部记录;fields;*
*字段序号表,为NULL复制全部字段*
*功能:复制fi文件的记录到fo文件,如fo与fi或者fields字段数.*
*对应字段类型.长度及小数不匹配,数据库会出错*
*返回值:fo文件实际记录数(注:必须调用DB_CLOSE关库后,文件记录才更新)*
***************************************************************************
*/
long db_cpyrec(DBFILE * fo,DBFILE * fi, long fosta, long fista, long n,
int * fields)
{
registerunsigned
long i;
unsigned
long p,q;
register
int j,k;
char * buf;
if ((buf = ( char * )malloc(fi -> stru.lrd)) == NULL) return 0l ;
if (db_goto(fo,fosta) == - 1l || db_goto(fi,fista) == - 1l ) return 0l ;
if ( ! n)n = fi -> stru.record - fista;
if ( ! fields){
for (i = 0l ;i < n;i ++ ){
if ( ! fread(buf,fi -> stru.lrd, 1 ,fi -> fdb)) break ;
if ( * buf == DELFLAG){
i
-- ;n -- ;
continue ;
}
if ( ! fwrite(buf,fo -> stru.lrd, 1 ,fo -> fdb)) break ;
}
}
else {
char * s, * p;
int m,h;
if ((s = ( char * )malloc(fo -> stru.lrd)) == NULL) return 0l ;
for (i = 0l ;i < n;i ++ ){
p
= s;
if ( ! fread(buf,fi -> stru.lrd, 1 ,fi -> fdb)) break ;
if ( * buf == DELFLAG){
i
-- ;n -- ;
continue ;
}
* p ++ = * buf;
for (m = 0 ;fields[m] >= 0 ;m ++ ){
for (k = 0 ,j = 1 ;k < fields[m];j += fi -> start[k].width,k ++ );
for (h = k,k = j,j += fi -> start[h].width;k < j;k ++ ) * p ++ = buf[k];
}
if ( ! fwrite(s,fo -> stru.lrd, 1 ,fo -> fdb)) break ;
}
free(s);
}
free(buf);
fo
-> stru.record = fosta + i;
return fo -> stru.record;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_FAPPEND*
*参数:starec:为被追加文件起始记录.其余参数同DB_CPYREC.*
*功能:追加fi文件的记录到fo文件尾部,其它同DB_CPYREC*
*返回值:fo文件实际记录数,其它同DB_CPYREC*
***************************************************************************
*/
long db_fappend(DBFILE * fo,DBFILE * fi, long starec, long n, int * fields)
{
return (db_cpyrec(fo,fi,fo -> stru.record,starec,n,fields));
}
/* **DB_CPYRE.CEND** */

/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_CREAT.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
" dbfio.h "
#ifdefTURBOC
#include
< alloc.h >
#else
#include
< malloc.h >
#endif
#include
< string .h >
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_VERIFIELD*
*参数:fd:外部字段结构数组首指针,末尾字段名首字符应为""*
*功能:检验并校正字段类型.长度和小数位*
*返回值:字段数*
***************************************************************************
*/
int db_verifield( struct dbf * fd)
{
register
int i,j;
for (i = 0 ;fd[i].name[ 0 ] && i < MAXFIELD;i ++ ){
if (fd[i].type > ' b ' && fd[i].type < ' o ' )fd[i].type -= 32 ;
if (fd[i].type != ' N ' )fd[i].dec = 0 ;
if (fd[i].width == 0 )fd[i].width = 1 ;
switch (fd[i].type){
case ' C ' :
if (fd[i].width > MAXFIESIZE)fd[i].width = MAXFIESIZE;
break ;
case ' N ' :
if (fd[i].dec > MAXDEC)fd[i].dec = MAXDEC;
if (fd[i].width > MAXWIDTH)fd[i].dec = MAXWIDTH;
if ((fd[i].width - fd[i].dec) < 2 )fd[i].width = fd[i].dec + 2 ;
break ;
case ' L ' :
fd[i].width
= 1 ; break ;
case ' D ' :
fd[i].width
= 8 ; break ;
case ' M ' :
fd[i].width
= 10 ; break ;
default :
if (fd[i].name[ 0 ]){
fd[i].type
= ' C ' ;i -= 2 ;
}
}
}
return i;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:db_create*
*参数:fname:文件名;fd:同上*
*功能:以写/读方式创建一个DBASE数据文件*
*返回值:成功DBFILE指针,出错NULL*
***************************************************************************
*/
DBFILE
* db_create( char * fname, struct dbf * fd)
{
DBFILE
* f, * db_findfile();
register
int n,i = 0 ;
if ((f = db_findfile()) == NULL) return NULL;
if ((f -> fields = db_verifield(fd)) == NULL) return NULL;
n
= sizeof (DBFIELD) * f -> fields;
if ((f -> start = (DBFIELD * )malloc(n)) == NULL) return NULL;
memset(f
-> start, 0 ,n);
if ((f -> fdb = fopen(fname, " w+b " )) == NULL){
free(f
-> start);
db_error
= 6 ;
return NULL;
}
/* 将定义的外部字段信息拷贝到内部字段结构中 */
for (n = 0 ;i < f -> fields;i ++ ){
strcpy(f
-> start[i].name,fd[i].name);
f
-> start[i].type = fd[i].type;
f
-> start[i].width = fd[i].width;
f
-> start[i].dec = fd[i].dec;
n
+= fd[i].width;
}
/* 初始化文件头结构 */
f
-> stru.dbf3 = DBFFILE;
f
-> stru.record = 0l ;
f
-> stru.ldb = f -> fields * 32 + 34 ;
f
-> stru.lrd = n + 1 ;
memset(f
-> stru.nul, 0 , 20 );
db_date(
& f -> stru);
if ( ! db_writestr(f, 1 )){
db_close(f,
0 );
remove(fname);
return NULL;
}
return f;
}
/* **DB_CREAT.CEND** */

/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_DEL.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
" dbfio.h "
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_DELETE*
*参数:f:DBASE数据文件指针;recs:记录号*
*功能:给记录打上删除标记*
*返回值:成功DELFLAG,出错EOF*
***************************************************************************
*/
int db_delete(DBFILE * f, long recs)
{
if (db_goto(f,recs) == - 1 ) return EOF;
return (fputc(DELFLAG,f -> fdb));
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_RECALL*
*参数:同DB_DELETE*
*功能:恢复打上删除标记的记录*
*返回值:成功SPACE,出错EOF*
***************************************************************************
*/
int db_recall(DBFILE * f, long recs)
{
if (db_goto(f,recs) == - 1 ) return EOF;
return (fputc( 32 ,f -> fdb));
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_PACK*
*参数:fname:DBASE数据文件名*
*功能:重新组合数据库,以去掉带删除标记的记录*
*返回值:成功0,出错非零*
***************************************************************************
*/
int db_pack( char * fname)
{
if (db_copy( " $$$$$$$$.$$$ " ,fname, 1 , 0l , 0l ,NULL)) return - 1 ;
if (remove(fname) == - 1 ) return - 1 ;
return (rename( " $$$$$$$$.$$$ " ,fname));
}
/* **DB_DEL.CEND** */

/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_SEEK.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
" dbfio.h "
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_GOTO*
*参数:f:DBASE文件指针;record:记录号=TOP首记录,=BOTTOM末记录*
*功能:移动文件指针到指定的记录号*
*返回值:成功:指针在文件的实际位置(字节数),出错-1*
***************************************************************************
*/
long db_goto(DBFILE * f, long record)
{
if (record == BOTTOM)record = f -> stru.record - 1 ;
if (record < 0 || record > f -> stru.record)record = f -> stru.record;
record
= record * f -> stru.lrd + f -> stru.ldb;
if (fseek(f -> fdb,record, 0 )){
db_error
= 7 ;
return - 1l ;
}
return record;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_GETRECNUM*
*参数:f:DBASE文件指针*
*功能:返回当前文件指针所在位置的记录号(注:指针不一定指在记录首字节)*
*返回值:记录号,出错-n*
***************************************************************************
*/
long db_getrecnum(DBFILE * f)
{
long record;
if ((record = ftell(f -> fdb)) == - 1l ){
db_error
= 7 ;
return - 1l ;
}
record
= (record - f -> stru.ldb) / f -> stru.lrd;
return record;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_SKIP*
*参数:f:DBASE文件指针;n:记录数*
*功能:文件指针从当前记录处移动N个记录位置*
*返回值:同DB_GOTO*
***************************************************************************
*/
long db_skip(DBFILE * f, long n)
{
long record;
if ((record = db_getrecnum(f)) == - 1l ) return - 1l ;
return (db_goto(f,record + n));
}
/* **DB_SEEK.CEND** */

/*
*********************DBASE数据文件操作C库文件************************
*文件名:DB_USE.C*
*编制人日期:湖北省公安县统计局毛泽发(1991.8)*
***************************************************************************
*/
#include
" dbfio.h "
#ifdefTURBOC
#include
< alloc.h >
#else
#include
< malloc.h >
#endif
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:db_getstr*
*参数:f数据文件指针*
*功能:读数据文件头信息*
*返回值:成功1,否则0*
***************************************************************************
*/
int db_getstr(DBFILE * f)
{
/* 读文件头结构 */
if ( ! fread( & f -> stru, sizeof (DBFSTR), 1 ,f -> fdb) || f -> stru.dbf3 != DBFFILE)
goto err;
/* 读字段结构 */
f
-> fields = db_getfields(f -> stru);
if ((f -> start = (DBFIELD * )malloc( sizeof (DBFIELD) * f -> fields)) == NULL)
goto err;
if (fread(f -> start, sizeof (DBFIELD),f -> fields,f -> fdb) != f -> fields){
free(f
-> start);
goto err;
}
return 1 ;
err:
db_error
= 3 ;
}
/*
*********************DBASE数据文件操作C库函数***********************
*函数名:DB_USE*
*参数:以读/写方式打开一个已存在的数据文件*
*功能:fname数据文件名*
*返回值:成功DBFILE文件指针,出错NULL*
***************************************************************************
*/
DBFILE
* db_use( char * fname)
{
DBFILE
* f, * db_findfile();
if ((f = db_findfile()) == NULL) return NULL; /* 数据文件打开数超过MAXFILES */
if ((f -> fdb = fopen(fname, " r+b " )) == NULL){
db_error
= 2 ;
return NULL; /* 文件不存在 */
}
if ( ! db_getstr(f)){
fclose(f
-> fdb);
f
-> fdb = NULL;
return NULL; /* 非DBASE数据文件或读文件头信息有错 */
}
return f; /* 返回文件指针 */
}
/* **DB_USE.CEND** */

Ok,欢迎大家光临!

更新(2008.8.6):果然贴漏了一个文件,现补齐在下面:

  1. /*
  2. *********************DBASE数据文件操作C库文件************************
  3. *文件名:DB_INIT.C*
  4. *编制人日期:湖北省公安县统计局毛泽发(1991.8)*
  5. ***************************************************************************
  6. */
  7. #include"dbfio.h"
  8. staticDBFILEdb_str[MAXFILES];/*DBASE数据文件指针数组*/
  9. staticcharinits=0;
  10. unsignedchardb_error=0;
  11. /*
  12. *********************DBASE数据文件操作C库函数***********************
  13. *函数名:initdbfstr*
  14. *参数:*
  15. *功能:初始化DBASE数据文件指针数组db_str[]*
  16. *返回值:*
  17. ***************************************************************************
  18. */
  19. voidinitdbfstr(void)
  20. {
  21. registerinti;
  22. undberror();
  23. for(i=0;i<MAXFILES;i++)
  24. db_str[i].fdb=NULL;/*文件指针初始化为NULL*/
  25. inits=1;
  26. }
  27. /*
  28. *********************DBASE数据文件操作C库函数***********************
  29. *函数名:db_findfile*
  30. *参数:*
  31. *功能:在db_str[]中查找未使用的文件指针*
  32. *返回值:成功DBFILE指针,否则NULL*
  33. ***************************************************************************
  34. */
  35. DBFILE*db_findfile(void)
  36. {
  37. registerinti;
  38. if(!inits)initdbfstr();/*初始化DBASE数据文件指针数组*/
  39. for(i=MAXFILES-1;i>=0&&db_str[i].fdb;i--);
  40. if(i==-1){
  41. db_error=1;
  42. returnNULL;
  43. }
  44. return(&db_str[i]);
  45. }
  46. /*
  47. *********************DBASE数据文件操作C库函数***********************
  48. *函数名:db_getfields*
  49. *参数:str文件头结构变量*
  50. *功能:计算数据文件字段数*
  51. *返回值:数据文件字段数*
  52. ***************************************************************************
  53. */
  54. intdb_getfields(DBFSTRstr)/*计算并返回文件字段数*/
  55. {
  56. return((str.ldb-34)/32);/*(文件头结构长-34)/32*/
  57. }
  58. voidundberror(void)
  59. {
  60. db_error=0;
  61. }
  62. /***DB_INIT.CEND***/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值