I need help in programming. The program has to accept a string that will eventually be turned to unsigned long. But here's the catch, there must be an error catcher that when you enter combination of hex and symbols like a!!!!!!
will produce an error and the unsigned long variable must be able to accept and store the input greater that 4294967295
which is FFFFFFFF
. I've tried this code segment:
char buffer[256];
unsigned long holder;
fgets(buffer,256,stdin);
holder = strtoul (buffer,NULL,16);
My problem is that when I enter FFFFFFFFF
(9 F's) instead of FFFFFFFF
(8 F's), the holder will STILL accept 4294967295
even though its more than the. Another thing is that when I combine both hex and symbols like a!!!!!
, the fgets
still consider the hex A.
Can you please give me an idea on how to do this? If you know any other idea besides this code, please do let me know. Thanks!