Okay, let me start over and see if we can get it...
#include "booksort.h"
Within "booksort.h" I have declared thus...
struct BOOKSORT {
char lpBook[MINNUM];
int iBook;
};
Now, in the same file, just under the above, I define the structure...
BOOKSORT bs[] = {
"gen", 0,
"exo", 1,
"lev", 2,
etc... to 190 book-int combinations in all, i.e., taking up all the canonical books, non-canonical books, dead sea scrolls, etc.
190 elements total. The int values increase by one, and these are there so I can sort the books according to canonical order. IOW, I'm simply mapping each book to an int, with "gen" being the first, "exo" the second, and so forth.
Now, this is a global declaration and a global definition in the header file, so all I have to do in my .cpp file is...
BOOKSORT sb[MAXENTRY]; // MAXENTRY is defined as 4096.
However, I also need the size of the bs array in the header files, so I do this...
const int BSTAGS = ((int) sizeof(bs) / sizeof(bs[0])); // from the bs struct in the header file
The reason I need this size is because I have to iterate through all 190 books to see if any of the strings in bs[x].lpBook match a string in sb[i].lpBook. For example...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
for(int i = 0; i < lrVerseNum; i++) // lrVerseNum is the count I got from the listbox
{
SendDlgItemMessage(hwnd, iListBox, LB_GETTEXT, i, (LPARAM)(LPSTR)chList[i]);
// find the order of chList[i] by
// comparing with bs structure, then
// put that data into the sb structure
// thus preparing the string for sorting
for(int x = 0; x < BSTAGS; x++)
{
if( strstr( chList[i], bs[x].lpBook ) != NULL )
{
sb[i].iBook = bs[x].iBook; // copy int to sb for comparison
strcpy_s(sb[i].lpBook, MINNUM, chList[i]); // put full verse in sb
break;
}
}
}
|
If so, I assign the correspoinding int value to sb[i].iBook so I can sort the structure according to canonical book order, i.e., according to the int values. I started, as you can see, with "gen", 0, then with "Exo", 1, and so on.
When the string matches in the iteration, I assign the appropriate int value so I can sort according to canonical order.
So, the point is, I need the size and the definition right off the bat, and the only way I can see to do this, without resorting to classes, is to declare and define the structure globally.
Does that make sense?