Still have a problem with locating a record in a dynamic array,
overwriting the field with a 'Q' and writing whole array to a file.
On examining the file a 'Q' is written to it but it writes it at the
beginning of the file not in the position denoted by the rec_num.
I've rewritten this part.
Anyone any ideas?
Also the search does find the correct record and where it is in the
master file.
Here's the code snippet:
static RECORD_DATA *search_file(char *key)
{
static RECORD_DATA record;
static RECORD_IDX *idx_list,
*entry_ptr;
register long recs;
FILE *fp_idx;
fp_idx=fopen("A:\STCKMAST.IDX","rb+");
fseek(fp_idx,IDXSIZE,SEEK_END);
recs = (ftell(fp_idx)/IDXSIZE);
/* use malloc(), create alist */
idx_list = (RECORD_IDX *)malloc(recs * IDXSIZE);
/*
{
printf("\nInsufficient memory available. This program will
close.");
pause();
exit(1);
} */
rewind( fp_idx);
fread(idx_list, IDXSIZE * recs,1,fp_idx);
rewind (fp_idx);
/* index = *entry_ptr; */
/* strcpy(index.key, key); */
qsort(idx_list, recs, IDXSIZE, compare);
strcpy(index.key, key);
entry_ptr = (RECORD_IDX *) bsearch(&index, idx_list, recs,
IDXSIZE, compare);
/* new bit */
if(entry_ptr)
{
switch(master.ARec.rec_type)
{
case 'z':
case 'Z': /* delete part num from index file */
index = *entry_ptr;
/* this bit causes Q to be written at the beginning of the file not
in the space found during the search */
strcpy(index.key, "Q");
printf("\n rec num %ld ",entry_ptr->rec_num);
/* entry_ptr->key[0]='Q';*/
/* write whole dynamic array to file */
fwrite(idx_list, (IDXSIZE * recs),1,fp_idx);
pause();
}