Extracting URL var and testing

If I send a URL to the AVR with a numeric value like /?var=76 I can extract the chars from the buffer array (they’re always in the same place) but cannot use the value.

What I need to do is take the value and act on it. I test it here

<...>

if (req_index < (REQ_BUF_SZ - 1)) {
          HTTP_req[req_index] = c;                // save HTTP request character
          req_index++;
        }

<...>

else if (StrContains(HTTP_req, "?chlorinatorNewPct=")) { //got new chlorinator setpoint
            client.println(F("Content-Type: text/plain"));
            client.println(F("Connection: close"));
            client.println();
            byte newPct[2];
            byte bin = 0;
            for (byte k=24;k<=26;k++) {
              client.print(HTTP_req[k]);
              newPct[bin] = HTTP_req[k];
              bin++;
            }
}

<...>

uint8_t chlorStep[] =    {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xA5, 0x00, 0x10, 0x20, 0x99, 0x04, 0x01, 0x05, 0x00, 0x00, 0x01, 0x78 };  // 5% chlorination

The browser successfully prints 76. So I got the number but it’s in a char array. In order to act on it I need to get it into a byte so I can insert it into another array (chlorStep) as the new value.

When I print the newPct[0] and [1] as HEX I get 3736. I see the correlation but not how I can take these two chars, convert them into a single byte to further process it.

Any thoughts?

http://www.cplusplus.com/reference/cstdlib/atoi/
documents the function:

int atoi (const char * str);

which ignores leading whitespace, handles an optional sign, and converts the input C string to an integer.

Notice that str must point to a string of characters that is terminated with a null character (0), or in this case any non-digit non-sign non-whitespace character.

Thanks for helping. So my char buffer is held in HTTP_req.
If I put:

int atoi (const char * HTTP_req);

how do I access the specific values?

Sorry, this isn't making sense, but I appreciate the help!

DOH! I got it. Thanks

            byte newPct[2];
            byte bin = 0;
            for (byte k=24;k<=26;k++) {
              client.print(HTTP_req[k]);
              newPct[bin] = HTTP_req[k];
              bin++;
            }

Copying 3 bytes into a two element array is not a good idea.

The atoi() function takes a NULL terminated array of characters. That means that the 3 characters will need to be copied to a 4 element array, AND that you’ll need to add a NULL terminator in the last position (’\0’).

It is often the case that you don't really need to copy the characters into a new array. You can blatt the delimiters with '\0' and use pointers to index into the array at the important places. The main exception to this is if your url contains url-escaped characters (+ and %), but even then it's not a huge deal: these can be decoded in-place after parsing out the querystring.

I should write some sample code and put it on the playground.