char* value to Hex number

This is a discussion on char* value to Hex number within the C++ Programming forums, part of the General Programming Boards category; I'm having some trouble with a program. I want the user to input a hex number as a char* pointer ...

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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    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.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    2
    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, 06:52 PM
  2. Replies: 6
    Last Post: 02-19-2009, 06: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, 10: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


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21