📄 kfs.doc
字号:
Required Fields
KFS_filename
Must contain the name of an open database.
area
The data area pointed to must contain the key of the
record being read.
Example
/* Read a KFS file by partial key (keypos=4, keylen=7) */
#include <kfs.h>
KFS_FILEINFO file1;
char recarea[100];
strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
KFS_Open(&file1);
if (file1.KFS_rc != KFS_OK)
printf("Error opening file1\n");
strcpy(&recarea[file1.KFS_keypos], "A k");
KFS_ReadGen(&file1, (void *)recarea, 3);
if (file1.KFS_rc == KFS_Key_Not_Found)
printf("We had no key match but got the next key\n");
else
if (file1.KFS_rc == KFS_OK)
printf("We got a record with a key starting with 'A
k'");
Possible KFS_rc Values -
KFS_OK
The partial key matched an existing record and this
record was read successfully.
KFS_Key_Not_Found
23
No record with a key that matched the partial key
specified was found. The next logical record in the
database is returned.
KFS_EOF
The partial key requested could not be found and the
next position in the database was end of file.
KFS_Key_Length_Invalid
A length greater than KFS_keylen was supplied in the
parameter list.
KFS_Invalid_Request
A KFS_ReadGen operation was attempted on a database
with numeric keys.
24
KFS_ReadGenNumeric(fs, area)
Read a numeric record, return the next record if not found.
Parameters -
KFS_FILEINFO *fs
A pointer to a KFS file structure.
void *area
A pointer to a data area where the requested record
will be read. A numeric key must be placed in
KFS_keypos of this area prior to performing the
operation.
Description
If a record in the database matches the key specified it is
read and placed in the data area. KFS_OK is then returned.
If no record matches the numeric key, then the next record
in the database is returned with a return code of
KFS_Key_Not_Found.
Required Fields
KFS_filename
Contains the name of an open database.
area
The data area pointed to must contain a numeric key at
KFS_keypos.
Example
/* Read a KFS file by numeric key (keypos=4) */
#include <kfs.h>
KFS_FILEINFO file1;
typedef struct m {
int f1;
int f2;
long mykey;
char filler[92];
} MYSTRUCT;
MYSTRUCT inarea;
strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
KFS_Open(&file1);
if (file1.KFS_rc != KFS_OK)
printf("Error opening file1\n");
inarea.mykey = 1000;
KFS_ReadGenNumeric(&file1, (void *)inarea);
if (file1.KFS_rc == KFS_Key_Not_Found)
printf("There was no key 1000 but got the next key\n");
else
if (file1.KFS_rc == KFS_OK)
printf("We got the record with key 1000");
Possible KFS_rc Values
KFS_OK
The record was read successfully.
25
KFS_Key_Not_Found
No record with a key that matched the key specified
was found. The next logical record in the database is
returned.
KFS_EOF
The partial key requested could not be found and the
next position in the database was at end of file.
26
KFS_ReadNext(fs, area)
Read the next record in keyed sequence in the database.
Parameters
KFS_FILEINFO *fs
A pointer to a KFS file structure.
void *area
A pointer to a data area where the requested record
will be read. The key placed at KFS_keypos of this
area must be the key of the record before the record
desired.
Description
Read the next logical record from a database. The record
with the next highest key after the key specified in the
data area will be read. The user must provide the key of
the previous record in KFS_keypos of area. This allows the
user to read all records in a database with a succession of
KFS_ReadNext functions.
Required Fields
KFS_filename
Contains the name of an open database.
area
Contains the key of the record previous to the one to
be read.
Example
/* Read the all of the records sequentially from a file */
#include <kfs.h>
KFS_FILEINFO file1;
typedef struct m {
int f1;
int f2;
char mykey[7];
char filler[89];
} MYSTRUCT;
MYSTRUCT inarea;
strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
KFS_Open(&file1);
if (file1.KFS_rc != KFS_OK)
printf("Error opening file1\n");
KFS_ReadFirst(&file1, (void *)&inarea);
while (file1.KFS_rc != KFS_EOF) {
KFS_ReadNext(&file1, (void *)&inarea);
if (file1.KFS_rc != KFS_OK) printf("Error");
}
KFS_Close(&file1);
Possible KFS_rc Values
KFS_OK
The record was read successfully.
27
KFS_EOF
There are no more records in the dataset.
KFS_Key_Not_Found
A record with the specified key did not exist in the
database and no record is returned. (i.e. the previous
record must be found before the "next" record can be
returned)
28
KFS_Replace(fs, area)
Replace the record with the specified key.
Parameters
KFS_FILEINFO *fs
A pointer to a KFS file structure.
void *area
A pointer to a data area containing the record that
will replace the record with the specified key in the
database.
Description
Replace the record with the corresponding key in the data-
base with the record in area. If the record does not exist
in the database, the operation is ignored and a
KFS_Key_Not_found is returned. No prior read of the record
being replaced must be done.
Required Fields
KFS_filename
Contains the name of an open database.
area
Contains the record that will replace the one in the
database.
Example
/* Replace a record in a KFS file */
#include <kfs.h>
KFS_FILEINFO file1;
typedef struct m {
int f1;
int f2;
char mykey[7];
char filler[89];
} MYSTRUCT;
MYSTRUCT inarea;
strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
KFS_Open(&file1);
strcpy(&inarea.mykey, "Oldkey");
/* Note - we would not have to read to replace */
KFS_Read(&file1, (void *)&inarea);
inarea.f2 = 77;
KFS_Replace(&file1, (void *)&inarea);
switch (file1.KFS_rc) {
case KFS_Key_Not_Found :
printf("Record was not in file");
case KFS_OK:
break;
default:
printf("Error replacing record");
}
29
Possible KFS_rc Values -
KFS_OK
The record was read successfully.
KFS_Key_Not_Found
A record with the key specified was not found. The
operation is ignored.
KFS_File_Error
An unknown error occurred when attempting to replace
the requested record.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -