1.While I am trying to display conv it is not showing anything, but when i print one one element using subscript i am able to see the contents.
2. Program to convert decimal to binary, octal, hexadecimal
#include<stdio.h>
int main()
{
convbase(23,2);
return 0;
}
int convbase(int num, int base)
{
char conv[33] = {' '};
char *ptr = &conv[32];
conv[32] = '\0';
do
{
*--ptr = "0123456789ABCDEF"[num % base];
num = num/base;
}while(num);
if(base == 16)
{
*--ptr = 'x';
*--ptr = '0';
}
if(base == 8)
{
*--ptr = '0';
}
printf("Decimal to base %d is :\t%s\n",base,conv);
return 0;
}