hello.
My question has to do with string tables. I want to be able to extract
the string associated with the ID. Can I do this in c? If I were
using C++/MFC, I could just simply use...
CString str;
str.LoadString(ID_NUM);
However, I can't use MFC in c. Can someone help?
Well, one method would be to define a struct which contains the ID and a
pointer to the string, and initialize an array of it:
typedef struct
{
int id;
char *str;
}
STRING_TABLE;
STRING_TABLE StringTable[] =
{
ID_FOO, "foo",
ID_BAR, "bar",
0,NULL
};
Then write your MyLoadString() function to search StringTable[] for the
specified ID. How you do this is up to you. If the table is going to
be large, you may want to require the table be sorted on ".id", and
then do a binary search to find the entry.
OT:
However, given that the MFC CString::LoadString() method in C++ actually
loads the string from disk, the above may not be what you _really_ want.
You may want the Windows LoadString() API call, for which you will need
to ask a Windows-specific newsgroup if you need further help.
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody |
www.hvcomputer.com | |
| kenbrody/at\spamcop.net |
www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:
[email protected]>