My goal is to convert a string such as "A1234"
to a long
with value 1234
. My first step was to just convert "1234"
to a long
, and that works as expected:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char* test = "1234";
long val = strtol(test,NULL,10);
char output[20];
sprintf(output,"Value: %Ld",val);
printf("%s\r\n",output);
return 0;
}
Now I am having trouble with pointers and trying to ignore the A
at the beginning of the string. I have tried char* test = "A1234"; long val = strtol(test[1],NULL,10);
however that crashes the program.
How do I set this up properly to get it pointing to the correct spot?