Reading 35 ascii characters from card reader track

Just posted this in another thread:

Arrch:
What you need is an array of chars:

const int maxLength = 50;

char readString[maxLength];




You also need an index variable (either global or static) that will keep track of where in the array you are.



int strIndex = 0;




And lastly, you need a character that will signal that you are done transmitting your string. This will depend on what program is sending you the string. The Arduino's Serial Monitor, for example can append '\r' and/or '\n' to the end of each transmission.



#define END_OF_STRING '\n'




From there you just need to read a character as you receive it and decide whether to parse the data and reset the array (if it's the END_OF_STRING marker):



// Do Something with the string
readString[0] = '\0'; // clear the array
strIndex = 0; // reset the index to 0




or add it to the array:



readString[strIndex] = inChar; // put the new char in the array
strIndex++; // increment our index for the next char
readString[strIndex] = '\0'; // null terminate our array to make it a proper string