Okay, I have actually two problems but after I get the first, I should be able to do the second. First, I have to write code to convert a hexadecimal to a decimal and its binary as well. The following code is what I have to fthe decimal conversion. Thanks for all of your help ahead of time, you guys are the smartest people on the planet. You can avoid main... It is just there for reference, and I know it works.
Code:
/* HEADER */
#define ARRAYSZ 128
enum mode_t { BINARY, DECIMAL, HEXADEC };
enum boolean_t { FALSE, TRUE };
int setmode(char, enum mode_t *);
enum boolean_t isBINARY(char *);
enum boolean_t isDECIMAL(char *);
enum boolean_t isHEXADEC(char *);
void bin2dec(char *, int *);
void dec2bin(int, char *);
void bin2hex(char *, char *);
void hex2bin(char *, char *);
int processBINARY(char *, enum mode_t);
int processDECIMAL(char *, enum mode_t);
int processHEXADEC(char *, enum mode_t);
main(int argc, char *argv[])
{
char *errmsg = "input error";
char string[ARRAYSZ];
int errstat;
enum mode_t imode = DECIMAL, omode = DECIMAL;
while (scanf("%s", string) != EOF) {
if (strncmp("?", string, 1) == 0) {
printusage(imode, omode);
errstat = 0;
} else if (strncmp("i=", string, 2) == 0) {
errstat = setmode(tolower((int)string[2]), &imode);
} else if (strncmp("o=", string, 2) == 0) {
errstat = setmode(tolower((int)string[2]), &omode);
} else {
switch (imode) {
case BINARY:
errstat = processBINARY(string, omode);
break;
case DECIMAL:
errstat = processDECIMAL(string, omode);
break;
case HEXADEC:
errstat = processHEXADEC(string, omode);
break;
}
}
if (errstat)
printf("%s\n", errmsg);
}
}
/*********************************************/
void hex2dec(char *string, int *dvalue) {
int slength,i;
int num[20],exp[20];
slength=strlen(string);
for (i=0; i<slength; i++) {
num[i]=string[i]-48;
}
for (i=slength; i>=0; i--) {
if (i==slength)
exp[i]=num[i];
else
exp[i]=16*num[1];
}
for (i=0; i<slength; i++)
dvalue+=num[i];
}
Thanks for any assistance you can give.