I'm still having problems with my program.
This is what the program should do:
There is a file which contains records which can be of 3 varying sizes. 'type' and 'code' are common to all 3 records. The program should allocate some memory for the records using malloc() and then sort the records using the 'code'. I have chosen the qsort function to do this.
The 'code' is declared as type char and consists of 4 numeric digits and a check digit on the end which could be an 'X' e.g. 2349X.
Thanks to Salem for the idea of using a typedef struct, however can I do this as one of the structures only consists of a 'type' and 'code'? e.g.
#define REC_SIZE ((int)(sizeof typedef struct))
char part_no ;
char quantity ;
char name ;
char address ;
char balance ;
char limit ;
struct ir_record old;
struct c_record create;
union customer details; /* the third record 'd_record' */
}; /*doesn't have any other part*/
/*only 'type' and 'code', therefore*/
/*will this still work or do I have to*/
/*revert back to using 3 structures*/
/*and a union - if so how?*/
typedef struct paint, *a_rec_ptr, *m_ptr;
unsigned long int no_of_recs, position; /*used to find info*/
a_rec_ptr = &paint; /*needed for qsort*/
m_ptr = a_rec_ptr;
/*some malloc() code should go here*/
qsort(m_ptr, no_of_recs, REC_SIZE, compare);
Also I am having a problem with the 'compare' function:
int compare(const void *a, const void *b)
return(strcmp((typedef struct*)a)->code, ((typedef struct*)b
/*I was told that I should use strcmp, is this because of the possibility of an 'X' on the end of the 'code'? Also what is the 'compare' doing? - books just don't give enough info. on it.