The proximate reason for 378282246310005 not being identified as Amex is this
number > (long) pow(10, 15)
is false. Remember pow(10,15) is a 16 digit number.
visual compare for the humans
I would not expect the posted code to loop back to the start; there is no loop in the code.