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



On Sat, 28 Oct 2006 18:34:21 -0400, nospam <nospam@xxxxxxxxxx> wrote:

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?

Which do you find easier to code and read later?

union{
struct {char c1[L1]}s1;
...
struct {char c30[L30]}s30;
}u
...
if (u.s19.c19[5] == 'x'){...}

or

#define POS19 5
char c[128];
...
if (c[POS19] == 'x'){...}


Remove del for email
.



Relevant Pages

  • 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 ... within contant bounds or a member of a list ...
    (comp.lang.c)
  • Re: knowing exact string array length ?
    ... many of these 50 characters are not being used. ... used in each array? ... fread is not a string oriented function. ... You are reading a struct. ...
    (comp.lang.c)
  • 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: <ctype.h> toLower()
    ... >> How do I apply this to an array of characters? ... struct T_DEF{ ... typedef char Array; ...
    (alt.comp.lang.learn.c-cpp)