Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Question (Integers) (http://www.go4expert.com/forums/question-integers-t27467/)

gatsbycollege 28Dec2011 14:55

Question (Integers)
 
Code:

void Dec2Hex()
{
    int n,r[10],i;
    printf("Enter a number to get its hexadecimal equivalent\n");
    scanf("%d",&n);
    for(i=0;n!=0;i++)
    {
        r[i]=n%16;
        n=n/16;
    }
    i--;
    for(;i>=0;i--)
    {
        if(r[i]==10)
            printf("A");
        else if(r[i]==11)
            printf("B");
        else if(r[i]==12)
            printf("C");
        else if(r[i]==13)
            printf("D");
        else if(r[i]==14)
            printf("E");
        else if(r[i]==15)
            printf("F");
        else
            printf("%d",r[i]);
    }
    printf("\n");
}

is it possible to increase the maximum input of conversion here?,, i cant convert decimal to hex that is exceeding 32k

xpi0t0s 29Dec2011 05:18

Re: Question (Integers)
 
Yes, but you can't use scanf %d. I suggest you use fgets to read whatever the user gives you, then convert whatever they give you to hex. It's not difficult.


All times are GMT +5.5. The time now is 06:52.