different sized data structures
Hi all!
youve probably seen this type of Q before, but i'm pulling my hair out with what might seem very a very trivial issue.
I have three data structures>>
struct issue_return_rec{
char part_num[7],
quantity[5];
};
struct create_rec{
char cust_name[21],
cust_addr[61],
cust_bal[10],
credit_limit[8];
};
union details{
struct issue_return_rec i_r;
struct create_rec crt;
};
typedef struct{
char rec_type;
char cust_code[6];
union details cust_rec;
}RECORDS;
I also have a file that holds varied sized records, a delete rec is 17 cahrs long a issue rec is 19 chars long and a create record that is 107 chars long.
The file has to be opened in binary format, then allocated memory, then its to be read from the allocated memory sorted then written to a newly sorted file.
The next part of my code is where i have the problem.......bare with me on this.
int main()
{
RECORDS trans; /*ident of struct*/
RECORDS *trns_ptr;
unsigned long int recs_num=0, file_size=0;
FILE *sort_fp, *valid_fp;
valid_fp = open_file("A:GJ23VF.DAT", "rb");
sort_fp = open_file("A:GJ23SD.DAT", "wb+");
fseek(valid_fp, 0L, SEEK_END);
file_size = ftell(valid_fp);
recs_num = file_size / sizeof(RECORDS);
/-*here's the problem*/
}
I know that the file that is being read has 160 records on it, ftell() returns 3040 bytes, now because the data in the file that i need to manipulate are of different sizes. recs_num will only hold 28 records, this is because of the sizeof(RECORDS).
So when i try to sort the records it only sorts 28 records
Is there another way to solve my problem of getting recs_num to hold the value of the correct amount of records.
thanks in adv