I am trying to pass a string to a Mid() function, return a portion of the string, and then convert that portion to an int. My attempt looks like this..
char * ReceivedStr;
char * Mid(char * inString, int Start, int Length );
main()
{
int i;
int dis;
char * Distance;
ReceivedStr = "Move125";
Distance = Mid(ReceivedStr, 4, 3);
dis = atoi(Distance);
}
//This function should return the middle section of a given string…
char * Mid(char * inString, int Start, int Length )
{
char outString[50];
int i, iOut;
iOut = 0;
for (i = Start; i < Start + Length; i++){
outString[iOut] = inString[i];
iOut++;
}
outString[Length] = '\0';
return outString;
}
Right before the mid function returns the value of outString is "152", but for some reason the line Distance = Mid(ReceivedStr, 4, 3); does not set Distance to "152".
Could someone please explain what I'm doing wrong?