RE: [Plib-users] legend update
Brought to you by:
sjbaker
|
From: Norman V. <nh...@ca...> - 2002-01-29 15:01:20
|
Stephen J Baker writes:
>
>> void sliderCB( puObject *sli) {
>>
>> float value;
>> char sliText[4];
>>
>> slicb->getValue(&value);
>> sprintf(sliText, "%.2f", value);
>> cout << sliText << endl; // this output is *exactly* what I need
>>
>> slicb->setLegend(sliText); // non-sense chars on the legend :(
>> ...
>> }
>>
>> No matter what I do to try and reformat the string (with sprintf),
>> prior to sending it on the legend, I get on my legend some strange
>> characters. What am I possibly doing wrong?
>> Can somebody see my mistake above?
>
>Someone already (correctly) pointed out that sliText is a
>local variable
>(which is certainly a problem) - but it's also not large enough.
>
>The '%.2f' format will generate things like '0.01' - four characters
>plus a '\0' byte - making five characters in all. Hence, sliText
>needs to have *AT LEAST* five elements - not four as you declared it.
Good Catch !
FWIW
I implemented a variation of this theme for the FlightGear
AutoPilot Gain adjuster.
http://www.vso.cape.com/~nhv/files/PLib/APDialog.jpg
The code while not the prettiest, works and should be adapatable
if anyone is interested see FlightGear / src / AutoPilot / auto_gui.cxx
which is accessible through the CVS web Interface
< follow link to CVS Resources @ www.flightgear.org >
Cheers
Norman
|