You need to know how the numbers are encoded in the file (one number per line? comma separated list? etc) and then read the relevant bytes from the file into a char array and parse the resulting string.

I only provide help via the forum - please do not contact me for private consultancy.

they are separated by commas. but how can I do that, is there a code or command to do that?

There are various approaches open to you, but the simplest one is to read the file character by character. If the character is not a comma, append it to a char array buffer. If it is a comma, parse the content of the buffer to a number and clear the buffer. This will give you a sequence of numbers read from the file. I assume you know what to do with the numbers from there on.

I only provide help via the forum - please do not contact me for private consultancy.

What is "that"? Google returned an overwhelming number of hits when searching for "that".

If you read the whole topic you will know what "that" is.

Quote

There are various approaches open to you, but the simplest one is to read the file character by character. If the character is not a comma, append it to a char array buffer. If it is a comma, parse the content of the buffer to a number and clear the buffer. This will give you a sequence of numbers read from the file. I assume you know what to do with the numbers from there on.

My difficulty is how to read character by character, after it is all the values are printed on the serial monitor I don't know how to read them.

// On the Ethernet Shield, CS is pin 4. Note that even if it's not// used as the CS pin, the hardware CS pin (10 on most Arduino boards,// 53 on the Mega) must be left as an output or the SD library// functions will not work.const int chipSelect = 10;

void setup(){ // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }

Serial.print("Initializing SD card..."); // make sure that the default chip select pin is set to // output, even if you don't use it: pinMode(10, OUTPUT);

// see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: return; } Serial.println("card initialized.");

// open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File dataFile = SD.open("path.txt");char array[4];int counter;int value;counter=0; // if the file is available, write to it: if (dataFile) { while (dataFile.available()) { array[counter] = dataFile.read(); if(array[counter] =','){ value = atoi(array); Serial.print(value); } counter++; } dataFile.close(); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } }

When using 'C' strings, you need to put a null character after the last character in the string. The functions such as atoi() that operate on strings use this to know where the end of the string is. Make your buffer array one element bigger, and write a null character at the end of the string. The easiest way to ensure this is always done is to write the null whenever you append a character.

You have a typo - you used '=' (assignment) instead of '==' (test for equality).

You don't really need to append the ',' to the buffer. It probably won't hurt, but to avoid any doubt test the character before you decide what to do with it.

So that you know what's going on, print out the content of the buffer as well as the value that atoi() gave you from it.

Just to be on the safe side, you should add a check that you aren't adding more characters to the buffer than it has space for.

It would probably be a good idea to check for any other characters and not just assume that anything that isn't a comma must be a digit, but if you wrote the file and know it doesn't have any spaces or line feeds or anything else in it then you might decide not to bother.

I only provide help via the forum - please do not contact me for private consultancy.