I'm currently working in my beginner's programming course project and in it I have to perform several searches in arrays of structures, for example I have these two different structures:
typedef struct{
char name[SIZE];
int number, year, isbn;
}magazine;
typedef struct{
char title[SIZE];
char author[SIZE];
int isbn, year;
}book;
As you can see, both book and magazine have isbn as a common element, and queries made with the isbn can be made for both data structures, my question is, how can I make (or use a glibc) function that is general purpose, without having to do this:
book *search_book(book *array, int key){
//We search a book by its isbn and return the pointer.
}
magazine *search_mag(magazine *array, int key){
//We search a magazine by its isbn and return the pointer
}
And instead be able to perform the search for both data structures in a single function?