Thread: char* value to Hex number

  1. #1
    Registered User
    Join Date
    Apr 2011
    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
    #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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    You mean you want to enter something like

    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Thanks for the Reply helped a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL DC Buffer Renders slow
    By Lane the Great in forum Game Programming
    Replies: 10
    Last Post: 01-07-2011, 07:52 PM
  2. Replies: 6
    Last Post: 02-19-2009, 07:19 PM
  3. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  4. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  5. string to hex
    By LogicError in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2005, 06:53 PM

Tags for this Thread