user16433: Can anyone explain how things like strtok() and strstr() can be used to provide a numeric value for a substring location position within the mainstring array.
I've tried to understand from the C++ examples, but their 'position' locations of the substring within the mainstring (which I need) are returned in C++ as %d variables, whereas all I can get returned by the arduino 'char * pointer=' is the actual substring chars if they exist, rather than a number for their start position locations within the mainstring.
The C++ examples show that it is possible to discover the position values from %d,  but how can I get that equivalent position value in arduino?
I want to be able to parse a char header[30] array for occurances of things like "s=123" and "d=789" in order to extract and assign the specified values to any appropriate variables (source or destination etc).

user11763: You have to define a format for the header you will be parsing and stick to that format. Say this is a sample header terminated by null:
s=123 d=789 e=463

A common property of each assignment in the string is the '=' symbol. You can use that to locate each variable and the value assigned to it. strchr is the function to use to locate a single character. Once you locate the = character, you move back and then forward along the array to obtain the variable and its value.
I will make some assumptions here: that your variable names will be single character, that numbers assigned will be no bigger than ints, and a space character is used to separate assignments.
char header[] = "s=123 d=789 e=463";

int d, s, e;   //your variables to be assigned to
char * ptr = header;
char * eq = NULL; //locate assmts
int * num = NULL; //just for starters
while (1){
  eq = strchr(ptr, '=');
  ptr = eq; // update the pointer
  if (ptr == NULL) // found no = chars
    break;
  switch (*(ptr - 1)){ 
    case 'd':    //all the possible variables
      num = &d; break;
    case 's': 
      num = &s; break;
    case 'e': 
      num = &e; break;
    default:   //unknown variable
      num = NULL;
  }
  ptr++;
  if (num == NULL) //unrecognized var
    continue;   // locate next = char
  *num = 0;
  while (*ptr && (*ptr != ' ')){  // while space or end of string not yet reached
    *num *= 10;  // extract each int
    *num += *ptr - '0';
    ptr++;
  }
}

Serial.println(d);  //now contains the numbers in the header
Serial.println(s);
Serial.println(e);

Untested but it should work for the header sample I gave.

16433: <p>Can anyone explain how things like strtok() and strstr() can be used to provide a numeric value for a substring location position within the mainstring array.</p>

<p>I've tried to understand from the C++ examples, but their 'position' locations of the substring within the mainstring (which I need) are returned in C++ as %d variables, whereas all I can get returned by the arduino 'char * pointer=' is the actual substring chars if they exist, rather than a number for their start position locations within the mainstring.</p>

<p>The C++ examples show that it is possible to discover the position values from %d,  but how can I get that equivalent position value in arduino?</p>

<p>I want to be able to parse a char header[30] array for occurances of things like "s=123" and "d=789" in order to extract and assign the specified values to any appropriate variables (source or destination etc).</p>
 11763: <p>You have to define a format for the header you will be parsing and stick to that format. Say this is a sample <code>header</code> terminated by null:</p>

<pre><code>s=123 d=789 e=463
</code></pre>

<p>A common property of each assignment in the string is the '=' symbol. You can use that to locate each variable and the value assigned to it. <code>strchr</code> is the function to use to locate a single character. Once you locate the = character, you move back and then forward along the array to obtain the variable and its value.</p>

<p>I will make some assumptions here: that your variable names will be single character, that numbers assigned will be no bigger than ints, and a space character is used to separate assignments.</p>

<pre><code>char header[] = "s=123 d=789 e=463";

int d, s, e;   //your variables to be assigned to
char * ptr = header;
char * eq = NULL; //locate assmts
int * num = NULL; //just for starters
while (1){
  eq = strchr(ptr, '=');
  ptr = eq; // update the pointer
  if (ptr == NULL) // found no = chars
    break;
  switch (*(ptr - 1)){ 
    case 'd':    //all the possible variables
      num = &amp;d; break;
    case 's': 
      num = &amp;s; break;
    case 'e': 
      num = &amp;e; break;
    default:   //unknown variable
      num = NULL;
  }
  ptr++;
  if (num == NULL) //unrecognized var
    continue;   // locate next = char
  *num = 0;
  while (*ptr &amp;&amp; (*ptr != ' ')){  // while space or end of string not yet reached
    *num *= 10;  // extract each int
    *num += *ptr - '0';
    ptr++;
  }
}

Serial.println(d);  //now contains the numbers in the header
Serial.println(s);
Serial.println(e);
</code></pre>

<p>Untested but it should work for the header sample I gave.</p>
