I have some code below that I am using to determine GPS location, by determining the amount of data in my serial buffer using gps.avaiable(), i then use that to create a string of the buffer size. When i try to write to that string in my for loop below, it works perfectly fine about six or seven times. Then randomly starts incrementing my for loop index almost exponentially? I really have no clue why this would be happening. My function below gets called about 6 or seven times, then you can see in my output where the for loop crashes.
void readGPS()
{
int numchars = 0;
int index = 0;
char *myString;
numchars = gps.available();
Serial.println("numchars");
Serial.println(numchars);
myString[0] = '\0';
if(numchars == 63)
{
myString = calloc(numchars, sizeof(char));
for(index; index < numchars - 3; index++) //(numchars > 0)
{
Serial.print(index);
Serial.print(",");
myString[index] = gps.read();
}
myString[numchars - 1] = 0;
myString[numchars] = '\0';
Serial.println(myString);
}
return;
}
You can see below here I am printing out the index of my for loop, and at the end you see in bold the index of my for loop changing crazily then the serial quits responding.
I can post my full code if necessary, but everything in my code works just fine, until i run this function.
numchars
63
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,3
$GPRMC,235755.00,A,2342.343451,N,134513.1345134,W,0.474,,1011
numchars
3
numchars
63
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,3
$GPRMC,235755.00,A,2342.343451,N,134513.1345134,W,0.474,,1011
numchars
9
numchars
63
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,3
$GPRMC,235755.00,A,2342.343451,N,134513.1345134,W,0.474,,1011
numchars
63
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,3
numchars
63
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,3
numchars
3
numchars
63
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,3
$GPRMC,235755.00,A,2342.343451,N,134513.1345134,W,0.474,,1011
numchars
3
numchars
63
0,1,2*
u`,3,4,5,6,7,8,68,11333,3288134,858926151,858926152,858926153,858926154,858926155,858926156,858926157,858926158,