How to store serial.print data instead of serial.print

So im trying to learn how to store my results, instead of serial.print. I dont have a specific example, but i run into it alot, and I dont know what I should even search for.

example....

if statement
serial.print ("1");
serial.print ("2");
serial.print ("3");

another if statement
serial.print ("4");
serial.print ("5");
serial.print ("6");

I am trying to get results from first and connect them to second. Again, no specific code, not looking for someone to fix my code, just tell me what its even called so I can search for info. I literally dont know what I dont know.

This is generally called data processing. The data is very often stored in something called a structure, often there are multiple structure formats with the start being common as in length and type followed by the types fields. Data can be stored on SD cards, hard and solid state drives, cloud servers and very often today in some sort fo SQL DB. A very good foundations book is https://amz.run/9V5r

How long do you want the stored values to be available for ?

  • until the Arduino is reset then forget them ?
  • stored so that they can be retrieved after the Arduino is reset ?
  • something else such as using the values in Excel ?

just so I can collect the info from if statements, and then serial.print them all at once.

like now i would get
123
123
123
ABC
ABC
ABC

and I want to collect the values of each, then display 123ABC (random example). Im pulling data from different sensors and want to just put the data together in one line. Maybe like a part number would be a good example. If I got data from first statement that told me part number started with AB, and then another gave date or something. And the goal would be to format it to AB2024. Sorry if im terrible at explaining it.

Read each value, put it in an array and increment the arrays index ready for the next value

When you have collected and stored the values that you want to output then iterate through the array, extract a value and print it

The key word that you are looking for is array

thank you.

Note that an array of variables can only hold data of a single type so if you want to save a string such as "ABC" and an integer value of 123 then they cannot be saved in the same array. You can, however, use two (or more) arrays, one for each data type

There is also a neater way of doing it using structs, but I am not sure of the data type or types that you need to store so I will not go into that at the moment

this could be done (quite easy with some tricks) but for your usecase I advice against it.

just think about another way:
first read your sensor values into variables
and when you have all sensor data, print your single line.

Make one big, flat, array to hold all the data. Know where in the array you put the data. No need to create little arrays or arrays of arrays.