Read String from Serial Input, parse it, and write it to the EEPROM.

PaulS:

Everytime the strncpy is executed my arduino is resetedand I have no idea why

Nor do I, since the code you posted doesn't call strncpy(). The usual culprit, though, is copying outside the bounds of the destination array. Copy 12 bytes into a 2 element array is not a good thing. Nor is copying to a location pointed to be a non-initialized pointer.

The comma variable should be named delimterCounter, so that it doesn't matter what the delimiter is.

Thanks for the tip related to the variable name. You are right and it is much more clearer that way :smiley:

But the strncpy is in fact called. If you look closely you will see that it is the first thing called after I check if the minimum number of colons is present.

Anyway thanks for the help. I was using wrong index values and now everything seems to work perfectly :slight_smile:

But now I have another question:

I have my code protected agains buffer overrun, but how can I validate my code against invalid input?

i.e:

Lets imagine that the user pass the following argument:

1:2:3:1:1:a:!:9

How can I parse the content and be sure I will only read numbers (preferably between 0 and 255)?

What I'm currently doing is using the atoi() function to parse the string, and everytime atoi() returns 0 I compare this value to the original string just to make sure that the "zero" wasn't actually the real value being passed (due to the fact that atoi() returns 0 everytime it wasn't able to parse the string into an int and this may be confused the a real zero).

Is this the most effective way of doing it?