Before I post pages and pages of code here, can anyone enlighten me on the circumstances which will cause an array to be given a value without my code distinctly assigning that value?
I have an array char EID[18] which is declared globally. Within the function below there is not even a mention of this array, but by debugging I figured out that it is within this function that EID gets assigned values I do not intend it to have. Before getfulltag() is executed, EID is assigned a value and properly terminated by '\0'. An example of EID's value is 982000421306548. After getfulltag runs, EID looks like this: 306564,21306548.
When debugging I see that EID changes in this way, each line showing a completed while (!fulltag) loop:
982000421306548
382000421306548
302000421306548
306000421306548
306500421306548
306560421306548
306564421306548
306564,21306548
( with 306564, being the characters being read from mastFile in the function getfulltag().)
void getfulltag()
{
Serial.print(F("1) EID before = "));
Serial.println(EID);
fulltag = false;
while (!fulltag)
{
eidtest[y] = mastFile.read();
if (eidtest[y] == 13) // get rid of all \n and \r within eid number
eidtest[y] = mastFile.read();
if (eidtest[y] == 10)
eidtest[y] = mastFile.read();
if (eidtest[y] == ',') // reset EID number if ',' is found
{
eidtest[0] = '\0';
y = 0;
}
if (eidtest[y] == '!') // reset EID number if '!' is found and ++ position of current eid record
{
eidtest[0] = '\0';
y = 0;
mastFileindex++;
}
if (eidtest[y] == ' ') // get rid of spaces in ALLFLEX eid nos
eidtest[y] = '\0';
if (isAlphaNumeric(eidtest[y])) // if valid eid character, put into array
y++;
if (y == 15)
{
eidtest[y] = '\0';
fulltag = true;
}
}
Serial.print(F("2) EID after = "));
Serial.println(EID);
}