Name: Jules 2012-03-20 16:56
hi guys, im here to ask for a favor that i know you people arent very fond of, but here it goes....AAAAAAAAAAAAAHHHHHHHHH!!!!!!! AAAAAHH!!! AHH!!....ok..the problem with this program is that its results are printed reverse. please provide hints..(or actual code) atoning for my mistakes. thank you. (basically, make my program work...please) thank you very much, and any help will be appreciated.
#include <conio.h>
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int converter(char number[], int base);
void main()
{
int a,base1,base2,i=0;
char rev[30],num[30];
char arr[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
printf("\nInput your number : ");
scanf("%s",num);
printf("\nInput the base of the current number : ");
scanf("%d",&base1);
printf("\nInput the base of which the number should be converted to : ");
scanf("%d",&base2);
a = converter(num,base1);
while(a>0)
{
rev[i] = arr[(a % base2)];
a /= base2;
i++;
}
rev[i]='\0';
printf("\nConverted Number is : %s\n",rev);
getch();
}
int converter(char number[], int base)
{
int decValue =0,i=strlen(number)-1,val,j=0;
while(i>=0)
{
switch(number[i])
{
case '0' : val =0; break;
case '1' : val =1; break;
case '2' : val =2; break;
case '3' : val =3; break;
case '4' : val =4; break;
case '5' : val =5; break;
case '6' : val =6; break;
case '7' : val =7; break;
case '8' : val =8; break;
case '9' : val =9; break;
case 'A' :
case 'a' : val =10; break;
case 'B' :
case 'b' : val =11; break;
case 'C' :
case 'c' : val =12; break;
case 'D' :
case 'd' : val =13; break;
case 'E' :
case 'e' : val =14; break;
case 'F' :
case 'f' : val =15; break;
}
decValue += ((int)pow((double)base,j)*val);
j++;
i--;
}
return decValue;
}
#include <conio.h>
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int converter(char number[], int base);
void main()
{
int a,base1,base2,i=0;
char rev[30],num[30];
char arr[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
printf("\nInput your number : ");
scanf("%s",num);
printf("\nInput the base of the current number : ");
scanf("%d",&base1);
printf("\nInput the base of which the number should be converted to : ");
scanf("%d",&base2);
a = converter(num,base1);
while(a>0)
{
rev[i] = arr[(a % base2)];
a /= base2;
i++;
}
rev[i]='\0';
printf("\nConverted Number is : %s\n",rev);
getch();
}
int converter(char number[], int base)
{
int decValue =0,i=strlen(number)-1,val,j=0;
while(i>=0)
{
switch(number[i])
{
case '0' : val =0; break;
case '1' : val =1; break;
case '2' : val =2; break;
case '3' : val =3; break;
case '4' : val =4; break;
case '5' : val =5; break;
case '6' : val =6; break;
case '7' : val =7; break;
case '8' : val =8; break;
case '9' : val =9; break;
case 'A' :
case 'a' : val =10; break;
case 'B' :
case 'b' : val =11; break;
case 'C' :
case 'c' : val =12; break;
case 'D' :
case 'd' : val =13; break;
case 'E' :
case 'e' : val =14; break;
case 'F' :
case 'f' : val =15; break;
}
decValue += ((int)pow((double)base,j)*val);
j++;
i--;
}
return decValue;
}