-
I'm having some trouble with a program. I want the user to input a hex number as a char* pointer and then have that char* converted to a hex value.
Here is what I got so far
Code:
#include <iostream>
using namespace std;
int main()
{
char hex[256];
char *HexNum;
cout<<"Enter the Hex number to Convert";
cin.getline (hex, 256,'\n');
HexNum = hex ;
cout <<"the string is"<<hex<<endl;
cout <<*HexNum<<endl;
return 0;
}
oh and thanks in advance for any and all help.
-
You mean you want to enter something like
0x100
or
100
and turn this into an integer like say decimal 256?
If you want continue using char arrays in your C++ program, then
strtoul(3) - Linux man page
But you might want to consider all the possibilities that string streams and extractors have to offer.
-
Thanks for the Reply helped a lot.