I am trying use the following code to convert a char to an int but it's not working.
For some reason PosToMoveTo contains 4000 instead of 4. I am not sure why...
main()
{
int i;
int dis;
char * Distance;
char N0, N1, N2, N3, N4;
int PosToMoveTo;
ReceivedStr = "P0004";
N0 = ReceivedStr[0];
N1 = ReceivedStr[1];
N2 = ReceivedStr[2];
N3 = ReceivedStr[3];
N4 = ReceivedStr[4];
switch(N0)
{
case 'R':
break;
case 'P':
PosToMoveTo = atoi(&N4);
if(MoveToPos(Po sToMoveTo) == 'T')
{
break;
}
break;
case 'T':
break;
default:
break;
}
Can someone please explain what I am doing wrong?
For some reason PosToMoveTo contains 4000 instead of 4. I am not sure why...
main()
{
int i;
int dis;
char * Distance;
char N0, N1, N2, N3, N4;
int PosToMoveTo;
ReceivedStr = "P0004";
N0 = ReceivedStr[0];
N1 = ReceivedStr[1];
N2 = ReceivedStr[2];
N3 = ReceivedStr[3];
N4 = ReceivedStr[4];
switch(N0)
{
case 'R':
break;
case 'P':
PosToMoveTo = atoi(&N4);
if(MoveToPos(Po sToMoveTo) == 'T')
{
break;
}
break;
case 'T':
break;
default:
break;
}
Can someone please explain what I am doing wrong?
Comment