you should, sometimes must, allow for the fact that your system might 'come alive' right in the middle of a data block transmission. so it's best to not process a block unless and until you have the right number of elements and the last or first datum received is provably the end or start of the block. if the data block does NOT have a specific start or end marker/character you can usually use time to determine the blocks. ASCII characters SOH .. EOT exist for good reason. I admit they don't get much use nowadays.
Delta_G:
No, the code you posted will not compile because it is not complete. You are missing loop and setup functions at the very least. Your while loop isn't in a function.
I did not post that part of the code because it's very long. I thought this is trivial.
I only posted the part where I need to save the serial data into the array.
Delta_G:
Don't copy the code from that thread. It probably won't work if you just copy it exactly. Instead, spend a few hours reading carefully through that thread until you understand the code in it. Then it will be trivial to do what you want.
If you really do what you should here then we shouldn't hear from you for a day or so. At least a few hours. If you come back from that thread in just a half an hour it makes it look like you're not trying very hard and that makes the help dry up.
The example you referred too is simple and it's different than the my problem. In the Robin example there is start and end characters.
Delta_G:
So you only posted part of the code. Now that severely limits those trying to help. They've either got to figure out what going on without any possibility to test or they have to write those sections and add to what you've given and what if they write something different from what you have?
If you have any any technical advices to solve the issue, you are most welcome to share. Otherwise, spare your lectures for yourself. Thanks.