# Function: strol

on
/*I can't seem to safely delete unused variables and strol doesn't seem to work?*/
/*am using Salford Plato V2.17*/

#include <iostream.h>
#include <clib.h>

{
private:
unsigned short int Offset,Segment;

public:
SegAdr(unsigned short int a,unsigned short int b);

unsigned short int GetSeg(void);
unsigned short int GetOff(void);
void OutputHex(unsigned short int);
unsigned short int Input(void);

};

{
Segment = a;
Offset = b;
}

{
Segment = a;
}

{

}

{
return Segment;
}

{
return Offset;
}

//takes a 4 digit hex number and turns it into a 16 bit number
{
unsigned short int w,x,y,z;
char values[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
w = a & 0b0000000000001111;
x = a & 0b0000000011110000;
x=(x >> 4);
y = a & 0b0000111100000000;
y=(y >> 8);
z = a & 0b1111000000000000;
z=(z >> 12);

cout<<values[z]<<values[y]<<values[x]<<values[w];

}
//Takes 16 bit number and converts it to 4 digit hexi number
{
//doesn't seem to work if you delete w,x,y?
char w,x,y,z;
char v[4],*c[4];
unsigned short int a[4],b;
int i,count=0;

char values[22]={'0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F','a','b','c','d','e','f'};
while (count<=3)
{
z=getch();

for (i=0;i<=22;i++)
{

if (z==values[i])
{
putchar(z);
c[count]=&v[count];
v[count]=z;
a[count]=strtol(c[count],NULL,16);
//strol seems to have some kind of weird cumulative error?
cout<<a[count]<<"a"<<endl;
count++;

}
}
}

b = a[0];
b=(b << 4);
b = b+a[1];
b=(b << 4);
b = b+a[2];
b=(b << 4);
b = b+a[3];

return b;

}

main ()
{
char d;
while (d!='q')
{
unsigned short int c,v;
/*cout<<"Please input number to convert into hex:";
cin>>c;*/
v=n1.Input();
n1.OutputHex(v);

d=getch();
}
return 0;
};

Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You're over writeing the values variable.
Your for loop should not be using a "<=" and should be using a "<" instead.
Example:
for (i=0;i<22;++i)

Continue.....

Commented:
You can not pass a NULL value to the second argument in strtol.
You need to pass a target variable.

Commented:
Disregard last comment.

Commented:
You're error is more then likely related to the over run problem with the for loop, and I previously mension in my first comment.

Commented:
You're also over writing variable v, c, and a.

These variables have a [4] length, but you're trying to write to the [23] position. (or 22 position in zero base)

Commented:
This question didn't show any activity for more than 21 days. I will ask Community Support to close it unless you finalize it yourself within 7 days.
You can always request to keep this question open. But remember, experts can only help if you provide feedback to their comments.
Unless there is objection or further activity,  I will suggest to accept

"Axter"