Thanks.
Why not just define result to be a character array instead of
going through doing a malloc, checking for null pointers, and
later freeing the location?
char result[15];
Maynard Lanting wrote:
you were right Ian, it now works fine, thanks for you help, for anyone
else’s interest in this (elementary) problem:
int runvar;
char * result;
int display_number( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t
*cbinfo )
{
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
if (ApName(widget)==ABN_butn0)
{
runvar =0;
result = malloc (15);
if (result ==NULL)
{
exit (EXIT_FAILURE);
}
sprintf(result, “%d”, runvar);
PtSetResource(ABW_display, Pt_ARG_TEXT_STRING, result ,0);
free (result);
}
“Maynard Lanting” <> mlanting@atsautomation.com> > wrote in message
news:3ba1fec6$> 1@ats2.sentex.ca> …
Ian:
I haven’t allocated buffer space? What do you mean? I have to use
malloc
or something like that?
Thanks for your response.
Maynard
“Ian Cannon” <> ianc@tecom.com.au> > wrote in message
news:> Voyager.010914083020.25266A@aresnode2.tecom.com.au> …
Previously, Maynard Lanting wrote in qdn.public.qnxrtp.photon:
So now i’m using the following code, but it kicks out as soon as i
click
on
butn0, could someone please tell me why?
/* Y o u r D e s c r i p t i o n /
/ AppBuilder Photon Code Lib /
/ Version 2.01 */
/* Standard headers */
#include <stdio.h
#include <stdlib.h
#include <unistd.h
#include <string.h
/* Local headers */
#include “ablibs.h”
#include “abimport.h”
#include “proto.h”
int runningvar;
char * st;
int display_number( PtWidget_t *widget, ApInfo_t *apinfo,
PtCallbackInfo_t
*cbinfo )
{
widget = widget, apinfo = apinfo, cbinfo = cbinfo;
if (ApName(widget)==ABN_butn0)
{
runningvar = 1;
you haven’t allocated buffer space for st
sprintf(st, “%d”, runningvar);
PtSetResource(ABW_display, Pt_ARG_TEXT_STRING, st ,0);
}
return (Pt_CONTINUE);
}
“Maynard Lanting” <> mlanting@atsautomation.com> > wrote in message
news:3ba12248$> 1@ats2.sentex.ca> …
I guess sprintf(…) would work right?
“Maynard Lanting” <> mlanting@atsautomation.com> > wrote in message
news:3ba11ec6$> 1@ats2.sentex.ca> …
Hello, i’m new to QNX and phAB so this may be a simple
question,
i’m
guessing it is because there has got to be an easy way to do
this:
I need to have a button clicked and a corrosponding number
(that
may
need
arithmetic calculations done on it) show up on the Label. So
i go
to
‘Resources’ for the label, go to ‘Label Type’ and find that
there
is
only
3
options: Pt_Z_STRING, Pt_IMAGE, and Pt_TEXT_IMAGE. The
closest
thing
would
be a Pt_Z_STRING and in the program i notice that i will have
to
use
the
following line:
PtSetResource(ABW_display, Pt_ARG_TEXT_STRING,“1”,0);
This will mean that i will have to change all the numbers i
take
in
to a
string before i display them. This would be a major pain.
\