C Programming: Convert Hex Int to Char*

后端 未结 4 1671
借酒劲吻你
借酒劲吻你 2020-12-21 05:55

My question is how I would go about converting something like:

    int i = 0x11111111;

to a character pointer? I tried using the itoa() fun

4条回答
  •  长情又很酷
    2020-12-21 06:46

    Using the sprintf() function to convert an integer to hexadecimal should accomplish your task.

    Here is an example:

    int i = 0x11111111;
    
    char szHexPrintBuf[10];
    
    int ret_code = 0;
    
    ret_code = sprintf(szHexPrintBuf, "%x", i);
    
    if(0 > ret_code)
    { 
       something-bad-happend();
    }
    

提交回复
热议问题