trivial: of string manipulationg in C

Hi,
I am writing a driver for Arduino so that Linux command it. Arduion must analyze commands like:
@Maxxxxbyyyyczzzz
where x, y, and z are integer place holders and a, b and c are sub-command characters.

I have problem of investigating the array for numbers. Testing the first char is easy, well, if(someArray[0]=='@'), but when it comes to extracting x-numbers for instance, I still get headache.

I'm wondering what strategy is the most efficient, but have this trivial solution:

  1. using "char *strchr(const char *, int);" locate 'a', register index
  2. using the same function again, locate 'b', register index
  3. define a new array with the length between registered indexes
  4. fill that array and convert it with atoi() function to integer.

Please point me out of this weak algorithm :smiley:

I'm wondering what strategy is the most efficient, but have this trivial solution:

  1. using "char *strchr(const char *, int);" locate 'a', register index
  2. using the same function again, locate 'b', register index
  3. define a new array with the length between registered indexes
  4. fill that array and convert it with atoi() function to integer.

That is a perfectly reasonable way to parse the array. The strtok function might be easier to use, though, as it does a lot of that stuff for you (find the next occurrence of a delimiter, allocate the array, and fill it).

If you go with your approach, don't forget to deal with the situations where b is not found and where a and b are adjacent to each other (i.e. the value is a zero length string).

The String class would also make some of the tasks easier (finding a position, allocating a substring).

Thank you PaulS, sure I consider points you stated kindly.