convert char to int

Hi, I have very basic question how can I convert char to int ? a get value from PtText and I want convert char to int.
I get this way.

char *textp;
PtArg_t arg[1];

PtSetArg( &arg[0], Pt_ARG_TEXT_STRING, &textp, 0 );
PtGetResources( ABW_PtText1, 1, arg );

Thanks for any replay.

int i=atoi(&textp)

While I like atoi for this example, I can’t resist showing an alternate.

int i=0;
...
if (sscanf(textp, "%d", i) !=1){
  // SOMETHING BAD HAPPENED, DEAL WITH IT.
}

-James Ingraham
Sage Automation, Inc.

Shouldn’t that be sscanf(textp, “%d”, &i) ? I thought the argument here must be a pointer, or have things changed since QNX 2?

Oops! You’re right. &i is correct.

Actually sscanf() is a bit heavy, I’m a fan to strtol() instead which allows you to convert different base values and also allows you to detect conversion errors.

Thomas