Add an additional check in the if
condition.
p_a_h==0 && (strlen(ptr)>1 || (strlen(ptr)==1 && ptr[0]!='0'))
I am making use of the fact that strtol
returns 0L
if the conversion is invalid(if the string contains non-digit characters). But checking for this alone, also skips if the actual string contains 0
. I leave the rest to understand it yourself.