IF command

Hello there

I'm trying to find out how can i create an IF() command to check in the argument that the user had entered is an hexadecimal number...any suggestions?Thank you
I suppose if( cin >> hex >> variable ) ...
closed account (zwA4jE8b)
the hard part about that is '11' could be eleven in decimal or seventeen in hex. You can check for the prefix like 0x11 the '0x' means the number following is hex.
11 could be n+1 in any base n. Because every base is base 10 :).
I don't really see a problem there. If you ask for a hex number, treat it as a hex number.
So thats my programm so i need an if to examin if the argument is hexadecimal :)




#include <stdio.h>
#include <stdlib.h>
#include <conio.h>


int main(int argc, char *argv[])
{
int param1,i,j;
char var[]
if (argc==1)
{

if (param1.. ) // Here is where i need your help !!!! !!! <<<<<<<<<<<<<<<<<<
{
param1=atoi(argv[1]);
itoa(param1,var,16);
printf("Your deciminal number is %s\n",var);


}
}
else
{
printf("Error in parametrs");
}
getch();
return 0;
}
Last edited on
@ hamsterman: I needed a double take but I got that one! Great joke, I'll have to steal it from you.

@ OP: Unfortunatly there is no lib to read the idiot users mind, you just have to tell them to do something (like format their input properly) and hope that they actually do it right.
closed account (zwA4jE8b)
that was a joke? I don't get it.
@ CreativeMFS: Every numerical system "promotes" after what it would see as the 10th integer. So for decimal it's 0 - 9 (10 ints, represented by the multi-character set "10") for hex it's 0-F (16 ints, but still represented by the multi-character set "10").
Last edited on
closed account (zwA4jE8b)
well when you spell it out like that.....
Computergeek01 wrote:
I'll have to steal it from you.
It's ok I stole it myself form http://tinyurl.com/6dg59re
Topic archived. No new replies allowed.