# Re: easy parsing problem in C for beginner

On Tue, 9 Feb 2010 17:58:37 -0800 (PST), John Mosby
<guywwillis@xxxxxxxxx> wrote:

First of all, thanks for your help. Maybe this will help clear some
things up.

What should s_Convert_Array actually do?

below is a representation of an array recieved from 4D

An example isn't of much use here - what is the _intention_ of the
routine? What is the purpose you want to achieve - why do you need a
plug-in?

As far as I can tell you're getting an array of time slot priorities
and a "difficulty", and somehow subtract the latter from the former, I
find it hard to understand why the 4D programmers left this as an
exercise for the user?

element 1 = "774774322333999666644333322555885000000666374446666311"
element 2 = "IIIIIIIIIIII000000000000000000000000000000000000000000"
element 3 = "AAAA55333633352444B99420000HHHHHHH00333463333114555855"
element 4 = "33333311111144433000PPPP000000000000000333330033888555"
element 5 = "5557742220006666631110000000000000000000KKKKKKKK000000"
element 6 = "777774533774111111111133222422222000000666693335555544"
element 7 = "666330666552444441322222000000000000333333666661777430"
element 8 = "333552666685522200000000000555552000000555584777555885"
element 9 = "333330555550111143522333444552222000000333111111444441"
element 10 = "555552333441333220000000666330000000000477774111222222"
element 11 = "222221544441666330333330000333330000000222222111666663"
element 12 = "333330111111433330333441111111000000000555330000777774"

Using the difficulty as 9 the following array is returned by the 4D
plugin (9 is subtracted from the ascii value of each position in all
12 elements)

IIRC, if the subtraction would go below '0', the result is replaced by
'0'? How high can "difficulty" go? Is it an actual value, or is it
following this same strange "digits, then letters" encoding scheme?

[snip]

why the two nested while loops?
As an inexperienced C "hacker" I was not able to get FOR loops to work
so I went with the WHILE loops and my own counter. I would rather use
FOR loops.

Example:

int dayCount = PA_GetArraySize(DayArray);
int day;
PA_Variable newDayArray = PA_CreateArray(dayCount);

// loop over all days
for(day = 0; day < dayCount; day++) {
// get current element
PA_Variable currentDay =
PA_GetArrayElementAtIndex(DayArray, day);

int characterCount = PA_GetArraySize(currentElement);

PA_Variable newDay = PA_CreateArray(characterCount);

// loop over characters
for(i = 0; i < characterCount; i++) {
char prio = PA_GetArrayElementAtIndex(currentDay, i);
prio = ComputeNewPrio(prio, difficulty);
PA_SetArrayElementAtIndex(newDay, i, prio);
}
SetArrayElementAtIndex(newDayArray, day, newDay);
}

Most of the PA_xxx routines are of my invention - they illustrate the
way you'll probably have to handle interop with the 4D types. Check
their documentation. ComputeNewPrio is your logic to substract a
difficulty value from a character.

you've been warned :-)
Yes, I know. I'm just trying to hack my way through this. I'm
working on it.

- caution with the sizeof(DayArray ). DayArray is of type PA_Variable,
and this:http://www.4d.com/docs/CMU/CMU84858.HTMtells me that that
is a struct containing a union - not suited to determine how many
characters are in that array.

Should I send the array length as another parameter? It will always
be 54 characters long with varying numbers of elements. Can't I just
make that assumption in the C code?

That depends on how "cast in stone" that constant is. Could it change
if the user configured another work day, e.g. from 8am to 8pm?

FinishedArray.uValue.fArray.fData[counter2] = slot_char; // store
the character back into the original array to be passed to 4D
//WARNING WHEN COMPILING... THE ABOVE LINE HAS THE WARNING...
// warning: assignment makes pointer from integer without a cast

AFAICT without knowing the 4D types, you're mixing levels of
indirection here - you have two-dimensional data (elements or lines or
strings, whatever you want to call them, and characters, difficulties
or priorities. You even have two nested loops to iterate over the
characters in the elements.

But you never actually use your first "counter" except to initialize
and increment it! Which means that you're not really accessing
characters at all - what you think is a character is probably a
pointer to the start of the array element.

Also, note that you're not handling 54, but 55 elements in your outer
loop.

I'm afraid you won't be able to "cheat" this. You'll need to learn the
basics of C, read the 4D interop docs, and also spend more time
_thinking_ about your problem before you start typing - the above two
problems have nothing to do with being unfamiliar with C.

Regards,
Gilles.

.

## Relevant Pages

• Re: sending echo to all clients
... I did initialize it up properly, ... There is only one array and that is an array of pollfd structures named ... as an array of characters only but then I can't because sendsends bytes ... you receive C-style strings, so there's really no point to doing it. ...
(comp.unix.programmer)
• Re: test if handle exists? How???
... > ishandlegives an array of nine 0s ... does not work because 'handles.c' is a literal character vector of 9 characters and that character vector is not an empty array. ... If what you are trying to do is find out whether there is a graphics object with the tag 'abcdef' then use ...
(comp.soft-sys.matlab)
• Re: Subquery Confusion
... Then I got this crazy idea that an Array can only contain a maximum ... number of characters, ... Then I decide that maybe I'm completely wrong with my query, ... it out of Excel VBA and spit it into Microsoft SQL Server Management ...
(microsoft.public.excel.programming)
• Re: test if handle exists? How???
... The problem is with the script but even replicating it on the command line ... ishandlegives an array of nine 0s ... does not work because 'handles.c' is a literal character vector of 9 characters and that character vector is not an empty array. ... If what you are trying to do is find out whether there is a graphics object with the tag 'abcdef' then use ...
(comp.soft-sys.matlab)
• Re: easy parsing problem in C for beginner
... Using the difficulty as 9 the following array is returned by the 4D ... so I went with the WHILE loops and my own counter. ... be 54 characters long with varying numbers of elements. ... 4D seems to have invented their own type system here, ...
(comp.sys.mac.programmer.help)