string table in c?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sherimarie@gmail.com

    #1

    string table in c?

    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!

  • Kenneth Brody

    #2
    Re: string table in c?

    sherimarie@gmai l.com wrote:[color=blue]
    >
    > 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?[/color]

    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::LoadSt ring() 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:ThisIsA SpamTrap@gmail. com>

    Comment

    • Flash Gordon

      #3
      Re: string table in c?

      sherimarie@gmai l.com wrote:[color=blue]
      > 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?[/color]

      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.
      --
      Flash Gordon
      Living in interesting times.
      Although my email address says spam, it is real and I read it.

      Comment

      Working...