Re: [Plib-users] legend update
Brought to you by:
sjbaker
|
From: Stephen J B. <sj...@li...> - 2002-01-29 14:34:38
|
> 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.
----
Steve Baker (817)619-2657 (Vox/Vox-Mail)
L3Com/Link Simulation & Training (817)619-2466 (Fax)
Work: sj...@li... http://www.link.com
Home: sjb...@ai... http://www.sjbaker.org
|