Hello ,

Here is my code. I revise it but why the putchar() can only display one character only ??

Please see the last part of the code .

Code:

#include<stdio.h>
main()
{
int i,j,ch,decimal,count,search;
int temp;
int hex[10];
int number[10];
i=0;
count=0;
decimal=0;
printf("Please enter your input in decimal form: ");
ch = getchar();
while(ch != '\n')
{
if('0' <= ch && ch <= '9')
{
decimal = decimal * 10;
decimal = decimal + (ch - '0');
}
ch = getchar();
}
printf("Input? %d\n",decimal);
while(decimal != 0)
{
hex[i] = decimal%16;
decimal= decimal/16;
printf("remainder is %d\n",hex[i]);
printf("after divided is %d\n",decimal);
i++;
count++;
}
i=i-1;
for(j=0; j < count; j++)
{
number[j]=hex[i];
i--;
printf("number[%d] is %c\n",j, number[j]);
}
printf("\n");
for(j=0; j < count; j++)
{
if(number[j]==0) {putchar('0');}
else if(number[j]==1) {putchar('1');}
else if(number[j]==2) {putchar('2');}
else if(number[j]==3) {putchar('3');}
else if(number[j]==4) {putchar('4');}
else if(number[j]==5) {putchar('5');}
else if(number[j]==6) {putchar('6');}
else if(number[j]==7) {putchar('7');}
else if(number[j]==8) {putchar('8');}
else if(number[j]==9) {putchar('9');}
else if(number[j]==10) {putchar('A');}
else if(number[j]==11) {putchar('B');}
else if(number[j]==12) {putchar('C');}
else if(number[j]==13) {putchar('D');}
else if(number[j]==14) {putchar('E');}
else if(number[j]==15) {putchar('F');}
j++;
putchar('\n');
}
}