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
    Likes Received:
    0
    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. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.