Hi I am capturing the serial data from LiDAR, i want to split the data in multiple string on the basis of count. For example i receiving continuous data, i want to split it into 3 array, initial 400 sample in array-1, then next 400 in array-2 and last 400 sample array-3, then again next 400 sample in array-1 and so on..
But OP wants 3 arrays not one.
Johnwasser example fits in that logic.
for (unsigned short i=0; i<400; array_1[i++]=getSample);
for (unsigned short i=0; i<400; array_2[i++]=getSample);
for (unsigned short i=0; i<400; array_3[i++]=getSample);
You're right, but it's not "one" array, it's a matrix. Also known as "array of arrays"..
With it OP might learn how to make parametric programs and avoid duplicates of identical objects (as a good programming practice). But if one likes spagetti coding, I'm ok with that.
I couldnt miss your two dimensional linear array.
But 2 separate arrays and one “2 dimensional“ array are not the same.
Just look at addresses of 2 dimensional array elements and you will see its 1 array with continuous addresses.
Only in high level its 2 dimension.
May be for some unknown reason OP wants them to be separated.
Have no idea why he wants 3 separate arrays. It could be done in many ways with matrix that u showed also in 1 array with delimiter after 400 chars, with mallocing and reallocing to have more dynamic array etc.
Generally speaking, yes. But IMHO 2 (or "n") arrays with fixed size and exactly the same size and data type are better stored in a matrix container. It also helps keeping the code parametric (if you need a fourth array you just change highest index). If needed, you could also have some constant symbols to distinguish between the arrays. I won't even mention memory allocation issues (I agree with your latest sentence) as OP doesn't need it.
PS: Anyway, every programmer has his own philosophy and programming mental scheme, so there's no point in trying to convince anyone else (except for other considerations like algorithm/processing speed, code compacting, source readability, and so on...)
Sometimes is a useful thing to better explain some programming techniques/philosophy if a small debate comes out, not for OP only but for future readers. But I agree it shouldn't go on for more than necessary, so I'll cut it down here.