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");
}
p
is unassigned, so it will never pass the first part of the test.
Since
p
is not assigned,
*p
is also undefined, and will probably start giving you access errors which will crash you application with many compilers.
Even if you set
p
to the user input in
buf
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!