IF command

May 8, 2011 at 5:36pm
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
May 8, 2011 at 5:54pm
May 8, 2011 at 6:08pm
I suppose if( cin >> hex >> variable ) ...
May 8, 2011 at 6:53pm
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.
May 8, 2011 at 7:10pm
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.
May 8, 2011 at 8:36pm
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 May 8, 2011 at 8:37pm
May 8, 2011 at 9:13pm
@ 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.
May 8, 2011 at 9:17pm
closed account (zwA4jE8b)
that was a joke? I don't get it.
May 8, 2011 at 9:23pm
@ 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 May 8, 2011 at 9:23pm
May 8, 2011 at 9:49pm
closed account (zwA4jE8b)
well when you spell it out like that.....
May 9, 2011 at 11:53am
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.