string table in c?

S

sherimarie

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?

Thanks!
 
K

Kenneth Brody

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]>
 
F

Flash Gordon

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?

This is highly Windows specific so you should ask in a Windows group.
There are plenty to choose from. Here we only deal with standard C and
not the specifics of all the many operating systems and libraries
available to use with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,489
Latest member
BrigidaD91

Latest Threads

Top