Searching trough an enumeration

Discussion in 'C Programming' started by Antoine Junod, Nov 13, 2005.

  1. Hello,

    I definitely have a problem to build a clean data structure. I would be
    very happy if some of you could help me as well as in the past.

    Here is my problem:
    -> I have a list of keywords.
    -> I would like to link each keyword with a string.
    -> I should be able to access the string of a given keyword via that
    keyword.
    -> I should have the ablity to know if a keyword is in the list of my
    keywords

    A way to link a string with a keyword is to define an enumeration with
    my keywords and index an array of char[] with these keywords.
    But that solution does not seem to permit to know if a given keyword is
    in my enumeration or not. Am I wrong with that?

    I could also define a structure with a field "keyword" and a field
    "string". Then I could build an array of that structure. With that
    solution I would be able to search trough the table if a given keyword
    is in my list of defined keywords with a simple for loop. But in that
    case I'm no more able to access directly a string via its keyword. And I
    think that is not really smart to build an enumeration with my keywords
    to index my structure... too much repetitions.

    Does someone has a better idea than me?
    Thanks a lot for your help
    -AJ
     
    Antoine Junod, Nov 13, 2005
    #1
    1. Advertising

  2. Antoine Junod wrote:
    > Hello,
    >
    > I definitely have a problem to build a clean data structure. I would be
    > very happy if some of you could help me as well as in the past.
    >
    > Here is my problem:
    > -> I have a list of keywords.
    > -> I would like to link each keyword with a string.
    > -> I should be able to access the string of a given keyword via that
    > keyword.
    > -> I should have the ablity to know if a keyword is in the list of my
    > keywords


    Perhaps something like:

    #include <stdbool.h>

    #define KEYWORD_MAX_LENGTH <some-value>
    #define KEYWORD_COUNT <some-value>

    #define KEYWORD_1 0
    #define KEYWORD_2 1
    ...

    struct {
    char string[KEYWORD_MAX_LENGTH + 1];
    bool present;
    } keywords[KEYWORD_COUNT];


    August

    --
    I am the "ILOVEGNU" signature virus. Just copy me to your
    signature. This email was infected under the terms of the GNU
    General Public License.
     
    August Karlstrom, Nov 13, 2005
    #2
    1. Advertising

  3. Antoine Junod wrote:
    > Hello,
    >


    [snip]

    > is in my list of defined keywords with a simple for loop. But in that
    > case I'm no more able to access directly a string via its keyword. And I
    > think that is not really smart to build an enumeration with my keywords
    > to index my structure... too much repetitions.
    >
    > Does someone has a better idea than me?
    > Thanks a lot for your help
    > -AJ
    >


    Your question is a bit off-topic here. comp.programming is a better
    place to ask this sort of question.

    If your keyword set is static, you may use gperf. Try gnu site for
    the documentation of gperf.

    Krishanu
     
    Krishanu Debnath, Nov 14, 2005
    #3
  4. > > Hello,
    >
    > [snip]
    >
    > > is in my list of defined keywords with a simple for loop. But in that
    > > case I'm no more able to access directly a string via its keyword. And I
    > > think that is not really smart to build an enumeration with my keywords
    > > to index my structure... too much repetitions.
    > > Does someone has a better idea than me?
    > > Thanks a lot for your help
    > > -AJ
    > >

    >
    > Your question is a bit off-topic here. comp.programming is a better
    > place to ask this sort of question.


    Sorry. I will try to better choose the newsgroup the next time.

    > If your keyword set is static, you may use gperf. Try gnu site for
    > the documentation of gperf.


    Thanks a lot. It is perfectly what I need :)
    -AJ
     
    Antoine Junod, Nov 14, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ivailokroumov

    Using FPGA trough internet

    ivailokroumov, Aug 17, 2004, in forum: VHDL
    Replies:
    2
    Views:
    520
    ivailokroumov
    Aug 17, 2004
  2. Maki

    seek trough files in vhdl

    Maki, Jan 24, 2005, in forum: VHDL
    Replies:
    0
    Views:
    960
  3. Sandra Castellanos

    Iterating trough controls

    Sandra Castellanos, Apr 30, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    325
    Teemu Keiski
    May 1, 2004
  4. Jurrie

    Iterate trough a string

    Jurrie, Oct 20, 2003, in forum: XML
    Replies:
    0
    Views:
    407
    Jurrie
    Oct 20, 2003
  5. puvit82
    Replies:
    4
    Views:
    762
    puvit82
    Feb 1, 2008
Loading...

Share This Page