Richard is right that your base is wrong, but ... look at your code
if (p == buf || *p != '\0')
printf("Invalid input: not a number\n");
is unassigned, so it will never pass the first part of the test.
is not assigned,
is also undefined, and will probably start giving you access errors which will crash you application with many compilers.
Even if you set
to the user input in
the the first part the test will succeed - so you will get the message - and even if that didn't happen, any non blank input by the user will make the second part pass.
So pretty much under all circumstances that code will either give you a message, or crash. You need to step back, think about what you are doing, and try coding that again - because what you have at the moment looks to me like "panic code" instead of "thought out" code!