byte2char

I'm writing a program that takes a hexidecimal value as stdin and then writes it to stdout as its ASCII counterpart. My code compiles, yet seems to choose when it wants to read an inputted value. Any help would be appreciated. Here is my code to take a look at.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    auto    char    hexVal;
    auto    int     result;

    do
    {
        result = scanf("%x ", &hexVal);
        if (EOF == result)
            {
            printf("error...\n");
            break;
            }
        printf("%c\n", hexVal);
        getchar();

    } while (1);

    return 0;
}


EDIT: Nevermind, I found my error, seems that the whitespace after %x in the scanf was throwing off the program.
Last edited on
EDIT: Nevermind, I found my error, seems that the whitespace after %x in the scanf was throwing off the program
No that shouldn't. whitespaces are allowed.

'%x' expects a pointer to an int. Providing a pointer to a char is wrong and might lead to a crash
Topic archived. No new replies allowed.