Re: easy parsing problem in C for beginner
- From: Gilles Kohl <gilles_delete_this@xxxxxxxxxxxxxx>
- Date: Mon, 15 Feb 2010 08:28:48 +0100
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]
As an inexperienced C "hacker" I was not able to get FOR loops to workwhy the two nested while loops?
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.
Yes, I know. I'm just trying to hack my way through this. I'myou've been warned :-)
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.
.
- References:
- easy parsing problem in C for beginner
- From: John Mosby
- Re: easy parsing problem in C for beginner
- From: Gilles Kohl
- Re: easy parsing problem in C for beginner
- From: John Mosby
- easy parsing problem in C for beginner
- Prev by Date: Anyone still have a copy of PowerMacInfo
- Next by Date: find a command in terminal
- Previous by thread: Re: easy parsing problem in C for beginner
- Next by thread: pshared and multiprocessing
- Index(es):
Relevant Pages
|