Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

halp

Name: Anonymous 2008-03-18 20:07

Just trying to figure out why this doesn't work, don't tell me to do it "this way", I'm not interested. 

//dectohex.c
//17/03/08 16:48

#include <stdio.h>

int main()
{
    printf("Input a whole number: ");
    int num;
    num=getchar();
    printf("The decimal number %d converted to hexidecimal is %x!", num, num);
    return 0;
}

============
outputs:
C:\hymn-c>dectohex
Input a whole number: 15
The decimal number 49 converted to hexidecimal is 31!
C:\hymn-c>

The only thing I can think of is that getchar() is incompatible with numerical input?  I dunno...

Name: Anonymous 2008-03-18 21:00

getchar() is receiving not 15, but 1. In the printf() you`re just outputting 1 converted to ascii in decimal, try changing %d to %c.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List