Re: Structures or Array Notation for many possible strings of finite length?
- From: "Malcolm" <regniztar@xxxxxxxxxxxxxx>
- Date: Sat, 28 Oct 2006 23:52:33 +0100
"nospam" <nospam@xxxxxxxxxx> wrote in message
I have an application that processes 30 kinds of strings of that fitA union of 30 types is pretty unwieldy, and generally unions are a bad idea.
in an array.
By processing, I mean
-check the value of certain characters or substrings to be
within contant bounds or a member of a list
-check the value of certain characters or substrings to be
within bounds defined by other characters or substrings
-call a series of functions based on value of certain
substrings.
Each kind of string has a different length, but it fits within an
array of 128 char's
Would you do the processing with array notation (using #defines for
the array indices) in order to write the clearest code , or would you
setup a union of 30 structs (one struct for each kind of sentence) to
write clearest code?
The string itself fits in an array, then presumably it needs to be tagged
with a type identifier. So I'd declare
typedef struct
{
char text[128];
int type;
} SENTENCE;
then
#define SIMPLEVERB 1
#define COMPOUNDSUBJUNCTIVE 2
or whatever you need.
Some code can presumable work on all sentences, some only on a subset. So
examine the type meber and process as appropriate.
--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.
.
- References:
- Prev by Date: Re: rolling dice
- Next by Date: Re: assembly in future C standard
- Previous by thread: Structures or Array Notation for many possible strings of finite length?
- Next by thread: Re: Structures or Array Notation for many possible strings of finite length?
- Index(es):
Relevant Pages
|