Q:

How to get a single character with sscanf

I'm trying to use sscanf to convert a single character from a string into its corresponding hex value.
#include <stdio.h>

int main () {
    char *str = "DEADBEEF";     
    int num;
    sscanf(str[2],"%x",&num);
    printf("%x",num);
}

When I try to compile, I get a warning because sscanf is looking for a char * rather than a single char. I could use the ampersand to get the address of the character (i.e. &str[2]) but that would read the rest of the string until it encounters a \0.

A:

Solved by lurker in a comment:
Using sscanf(&str[2], "%1x", &num); you can read a single character rather than as large of an integer as sscanf can read

