How to convert string contain Hex data into integer

Discussion in 'Software' started by asifjavaid, Sep 9, 2008.

  1. asifjavaid

    asifjavaid

    Joined:
    Sep 9, 2008
    Messages:
    1
    hi all,

    I want to convert a string contain hex format '0x15' and what to convert it integer because i want to write data contain by a integer variable in hex format (binary data) into the file.

    here is my code

    char * str = "0x15";
    int value;

    FILE FILE *fptrSample = fopen("e:\\sample.txt","rb+");
    if (fptrSample)
    {
    value = atoi(str);// error : - here "str" contains hex data and want output value = 0x15 in integer but value = 0

    putc(value,fptrSample);
    fclose(fptrSample);
    }

    after executing this
    output is
    value = 0

    where as i want to the correct output
    value = 0x15 so that this binary data will be written in file


    can any one help me?.................
     
    asifjavaid, Sep 9, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil
    Replies:
    0
    Views:
    729
  2. kemp
    Replies:
    2
    Views:
    743
    Frisbee®
    Oct 13, 2006
  3. mona@rona.com

    What files contain specific user data?

    mona@rona.com, Aug 2, 2007, in forum: Computer Support
    Replies:
    2
    Views:
    474
    pcbutts1
    Aug 2, 2007
  4. newasp.net
    Replies:
    1
    Views:
    1,668
    imransyed63
    Aug 21, 2008
  5. kendarak
    Replies:
    0
    Views:
    1,152
    kendarak
    Jul 12, 2009
Loading...

Share This Page