You're using strtol()
incorrectly, the last parameter should be the base that you want. For example if you want to store that number in base 10 (decimal):
long pnumber;
pnumber = strtol("09195462965", NULL, 10); //nst char *nptr is "09195462965"
//char **endptr is null
//int base is 10 for decimal
printf("n: %ld",pnumber);
>> 9195462965
Make sure you read the man page for the function you're using.
Passing pnum
(which is set to 0
) as your doing for the last parameter is causing it to spit back "0", because of the number you're passing in.
09195462965 has digits from 0-9 (so I assume you wanted dec) if you pass in "0" to strtol()
then it's going to see that first 0
and will treat the number has octal, the problem with that is that octal numbers go from 0-7, thus the 9's are "out of bounds" for an octal number and as such strtol()
spits back 0.
with a number like: 07175462765
, you'd be fine to pass in pnum
when it's 0.