473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Searching trough an enumeration

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

Nov 15 '05 #1
3 1396
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.
Nov 15 '05 #2
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
Nov 15 '05 #3
> > 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
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christopher R. Barry | last post by:
I need to search and replace multiple words in one pass of an input stream or string. For example, given the input: "The quick brown fox jumped over the lazy dog's back" and given the...
1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
1
by: Andrés Giraldo | last post by:
Hi! I'm trying to pass trough all the objects of a form but I have some text inputs in a DIV and I have many DIVs like this on my form. I'm doing something like: for (i = 0; i <...
0
by: Javier de la Torre | last post by:
Hi all, I'm wondering if someone has experiment problems using SQL statements with UNIONS trough the ODBC driver. For example this SQL statement: (SELECT DISTINCT compactes.numplec AS UnitId...
0
by: Bas Hamer | last post by:
Ok, I'm trying to build a search framework to look trough our propritory logfile format. The logfiles have a dynamic setup so I generate most of my tables on the fly. I currenlty have the code...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
4
by: Nedim | last post by:
first let me say sorry if this is in the wrong place, i'm pretty new to programming and to be honest i am a bit intimidated by these forums. now that i've got that out of the way, i was bored and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.