Substrings with char arrays

I'm working on a project to read CSV data over a serial connection, reformat the first field to a human-readable date, and write the resulting data to an SD card. The lines of data can be up to around 150 characters long, so they're read into char input_line [160].

By stepping through input_line, I can find the first comma, and then do my conversion on the contents of the first field, storing the result in char dataTimeString [20]. Once I've done that, I need to print out the rest of input_line, from the first comma to the end of the line.

So, with apologies for the simple question, how do I do that? I see documentation on the String class, but I understand that is a bit of a resource hog, which is why I'm using the char arrays. I'm sure there's a simple function to do this, but I'm not sure where else to look to find it.

I'm sure there's a simple function to do this, but I'm not sure where else to look to find it.

There are couple of ways to do this. The easiest to understand is to print one character at a time.

The other approach is to create a char pointer (char *ptr;), and make that pointer point to the first element in the array that you want to print.

ptr = charArray[20];

would make ptr point to the 21st element in the array. If you then print prt, it will print from the 21st element of the array to the NULL that terminates the array.

State machines are good at parsing long input lines:

Serial.println((char *)&input_line[20]);

majenko:

Serial.println((char *)&input_line[20]);

That did the trick. Thanks!

Nick, I'd seen your page, and used your code for reading the line, but the discussion of state machines went a bit over my head--I'm still pretty green to Arduino (and to C-like languages).