On Thu, Apr 16, 2009 at 1:07 AM, Harry Campigli wrote:
>
>
>
> How fo write an FG string property from an indexed string in a structure?
>
> Possibly someone can help please , I have tried to find an example with no
> luck, I am sure i had it working yesterday but now every way i try i end up
> with it wrong at compile, a seg fault or a property node with an empty
> string. The basic setup works fine with doubles ect, here i only show the
> string code.
>
>
> Its wrong, but this is what i want to do, where : index i is declared as an
> int, path is a node, and path[i] is a string indexed in the structure
> called buf- node->setStringValue("path",buf->path[i]);
> )
>
> 1-The stucture called buf with indexed stings in it from the h file
> >
> enum {
> FG_MAX_AIRCRAFT = 25
> };
> uint32_t num_aircraft;
> string callsign[FG_MAX_AIRCRAFT];
> string path[FG_MAX_AIRCRAFT];
> >
>
>
> 2- I write to the stucture with
>
> >
> tempnode = node->getChild("path");
> if ( tempnode != NULL ) {
> net->path[i] = tempnode->getStringValue();
> }
>
> >
At a glance, this looks like it should work. I believe getStringValue()
returns a const char * type and you should be able to assign this to a
"string" variable like you show in your example code.
If I was going to dig into this, I might start inserting some printf()'s to
dump out the value of tempnode->getStringValue() to make sure that is sane.
Make sure [i] is a sane index value, etc. Off by one errors are pretty easy
to accidentally introduce. Hehe, I still have trouble with those off by an
order of magnitude errors ... :-)
Without seeing your surrounding code, I think I would be most interested in
first checking the value of "i". That should remain between 0 and 24 (i=25
would be an array overrun because you'd be referencing the 26th element of
the array.)
Best regards,
Curt.
--
Curtis Olson: http://baron.flightgear.org/~curt/
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel