Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get a char from a hex code stored in a character pointer in C?

How can I get a char in C that corresponds with a hex code stored in a character pointer?

For example, in the below, I have "2A" in char pointer hex. How do I get the * character from this?

int main() {  
char* hex = "2A";

return 0;
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Have you tried strtol?

#include <stdio.h>
#include <stdlib.h>

int main () {
    char *hex = "2A";
    printf("%c\n", (char)strtol(hex, NULL, 16));

    return 0;
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading