I have a program that reads an inventory binary file, loads the part_id and offset (via the "index_fill" function)into an array called "index", sorts "index", and should print the whole binary file with the complete record associated with each part_id. I get an error when passing the "index" array to my sort routine.
I have the following declarations at the beginning of the program:
//fills array
/*index_t is a struct consisting of the part_id and the offset*/
//array of index structs
In the main function:
/*"source" is the file pointer to the source file;
"index_fill" function fills the array "index" and returns the number of records read from the file */
//this works fine
//error occurs here
the sort_index routine:
//ID_LENGTH is 7, rec_count came from index_fill
//for testing only, print to verify order
//ERRORS HERE
I have realized while writing this that the array of structs could be passed with pointers but I'm alittle pressed for time to get that working properly. When I get to the printf in sort_index I get an "unhandled error: access violation" error. I'm writing this in MS Visual C++.
Thanks in advance.
I have the following declarations at the beginning of the program:
Code:
#define MAX 50
int index_fill(index_t index[], FILE *INV);
/*index_t is a struct consisting of the part_id and the offset*/
Code:
index_t index[MAX];
Code:
index_t sort_index(index_t idx_file[], int rec_count);
index_t idx_file[MAX];
In the main function:
/*"source" is the file pointer to the source file;
"index_fill" function fills the array "index" and returns the number of records read from the file */
Code:
num_of_recs = index_fill(index, source);
Code:
sort_index(index, num_of_recs);
the sort_index routine:
Code:
index_t
sort_index(index_t idx_file[],int rec_count)
{
int i;
//ID_LENGTH is 7, rec_count came from index_fill
Code:
qsort(idx_file, rec_count, ID_LENGTH, compare);
//for testing only, print to verify order
Code:
for(i = 0; i < rec_count; i++)
printf( "%s\n", idx_file[i]);
Code:
return 0;
}
I have realized while writing this that the array of structs could be passed with pointers but I'm alittle pressed for time to get that working properly. When I get to the printf in sort_index I get an "unhandled error: access violation" error. I'm writing this in MS Visual C++.
Thanks in advance.