ok so this program has two functions the first one"void itox" converts interger to hexastring and second one 'int xtoi" converts hexstring to its own value.
The whole code I have is this and I'm having problems compiling
Code:
#include <stdio.h>
#include <string.h>
#include "xbits.h"
#define YES 1
#define NO 0
/* function converts int n to a hexstring */
void itox (char hexstring[], int n)
{
char hexdigit[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E\
','F'};
int index = 0;
int remain;
printf("in itox, processing %d\n", n);
while(n > 0) {
remain = n%16;
n/=16;
hexstring[index++] = hexdigit[remain];
}
hexstring[index] = '\0';
printf("decimal: %d\thexstring %s\n", n, hexstring);
}
/* converts a hexstring to its int */
int xtoi (char hexstring[])
{
int hexdigit, i, inhex, n;
i=0;
if(hexstring[i] == '0') {
++i;
if(hexstring[i] == 'x' || hexstring[i] == 'X') {
Code:
int xtoi (char hexstring[]){
int hexdigit, i, inhex, n;
i=0;
if(hexstring[i] == '0') {
++i;
if(hexstring[i] == 'x' || hexstring[i] == 'X') {
++i;
}
}
n = 0;
inhex = YES;
for(; inhex == YES; ++i) {
if(hexstring[i] >= '0' && hexstring[i] <= '9') {
hexdigit = hexstring[i] - '0';
}else if(hexstring[i] >= 'a' && hexstring[i] <= 'f') {
hexdigit = hexstring[i] - 'a' + 10;
}else if(hexstring[i] >= 'A' && hexstring[i] <= 'F') {
hexdigit = hexstring[i] -'A' + 10;
}else{
inhex = NO;
}
if(inhex == YES) {
n = 16 * n+ hexdigit;
}
}
return n;
}
errors are
Code:
error: expected =, ,, ;, asm or __attribute__ before void void itox (char hexstring[], int n)
^
error: expected =, ,, ;, asm or __attribute__ before { token
{
^
error: expected { at end of input
}