Re: Structures or Array Notation for many possible strings of finite length?



"nospam" <nospam@xxxxxxxxxx> wrote in message
I have an application that processes 30 kinds of strings of that fit
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?

A union of 30 types is pretty unwieldy, and generally unions are a bad idea.

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.


.



Relevant Pages

  • Re: Need help which way is fastest to pick out a segment from a string
    ... There may just be a little to gain by pulling the data into a Byte array and dealing with it as raw byte data, but for this specific task I very much doubt that it will be much faster. ... I have just created an array of 200,000 strings of random characters each with a length varying randomly between 36 and 72 characters and with the first space character in each string varying randomly in the range 12th to 32nd character position. ... If I then run a code loop on that array of 200,000 strings extracting the substring you have requested the code deals with the entire array, returning all 200,000 substrings, in just one tenth of a second. ...
    (microsoft.public.vb.general.discussion)
  • Structures or Array Notation for many possible strings of finite length?
    ... I have an application that processes 30 kinds of strings of that fit ... in an array. ... -check the value of certain characters or substrings to be ...
    (comp.lang.c)
  • Re: Structures or Array Notation for many possible strings of finite length?
    ... in an array. ... -check the value of certain characters or substrings to be ... setup a union of 30 structs to ...
    (comp.lang.c)
  • Re: I keep getting this question on beginner study sheets...
    ... Then iterate over the array from the end to the ... to reassemble the substrings into the order you want. ... > The question is how do you reverse the words in a string? ... > space-seperated words around(is that even possible? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Determining array length with split function
    ... Dim asMyText() As String ... 'Splitalways returns a 0-based array. ... determining the number of substrings in any given array to avoid ...
    (microsoft.public.word.vba.general)