By example, what should i put instead of that.
char val[10];
(If the record length does not exceed 10 characters. If it does, make the value larger.)
this must be deleted?
No. You need an index into the array. That index should be incremented as the character is added. Don't keep overwriting position 0.
how to create a non-NULL-terminated array?
That's not what you want. You want a NULL terminated array of characters.
and a end of record marker ?
That needed to be done when the file on the SD card was created. What does the file look like?
Here is some code that reads from the serial port. It expects the data to be bounded by start and end of packet markers. Reading from a file is simpler, since you know when "the start marker arrives". That happens when you open the file, and after processing each record in the file.
The end of packet marker is probably a carriage return or linefeed (\r or \n).
#define SOP '<'
#define EOP '>'
bool started = false;
bool ended = false;
char inData[80];
byte index;
void setup()
{
Serial.begin(57600);
// Other stuff...
}
void loop()
{
// Read all serial data available, as fast as possible
while(Serial.available() > 0)
{
char inChar = Serial.read();
if(inChar == SOP)
{
index = 0;
inData[index] = '\0';
started = true;
ended = false;
}
else if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 79)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
// We are here either because all pending serial
// data has been read OR because an end of
// packet marker arrived. Which is it?
if(started && ended)
{
// The end of packet marker arrived. Process the packet
// Reset for the next packet
started = false;
ended = false;
index = 0;
inData[index] = '\0';
}
}
You should be able to adapt this to reading from a file, instead of the serial port.