Using KSAM/XL and KSAM 64 (32650-90886)
Appendix C 269
HP C/iX Example Program
}
static void update_records(void)
{
/* Update department code for several employees */
const struct {char empno[5]; char new_dept[4];} update_data[] =
{{"28766", "9901"}, {"11111", "9905"}};
const int update_items =
sizeof update_data / sizeof update_data[0];
int i;
record_t buffer;
for (i=0; i<update_items; ++i)
{
printf("Updating employee %.5s to department %.4s: ",
update_data[i].empno, update_data[i].new_dept);
lock_file();
FREADBYKEY(filenum, buffer, - sizeof buffer,
update_data[i].empno, 0);
assert(ccode()==CCE);
printf("%.20s\n", buffer+5);
memcpy(buffer+34, update_data[i].new_dept, 4);
FUPDATE(filenum, buffer, - sizeof buffer);
assert(ccode()==CCE);
unlock_file();
}
printf("\n");
}
static void write_new_records(void)
{
/* Add some entries to the file */
const record_t test_data[] =
{
"77777NEWMAN GEORGE 7770066661520871012",
"55555GOODMAN BRIAN 5553300008540880815",
"66666MANLEY SHAUNA 0003526143360890930"
} ;
const int test_items = sizeof test_data / sizeof test_data[0];
int i;
for (i=0; i<test_items; ++i)
{
lock_file();
write_record(test_data[i]);
unlock_file();
}
printf("\n");
}
static void write_record(const char * const record)
{
/* Write one record to the file */
printf("Writing record for %.5s, %.20s\n", record, record+5);
FWRITE(filenum, record, - sizeof(record_t), 0);
assert(ccode()==CCE);
}