title: Why does adding an int to this char array not add the ASCII character of the same value?
body: <p>I've been working on a URLdecode function so I can parse POST requests received on an HTTP server, however I've ran into a hiccup. Whenever I add an integer to an array, it is not adding the integer's ASCII counterpart. Is there something I'm missing?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  void copyAndTerminateString(char *dest, char *src, int len) {
      if (len &gt; 0) strncpy(dest, src, len);
      dest[len] = '\0';
  }
  
  char *urldecode(char *encodedString) {
      int i, n = 0, val, encodedStringLen = strlen(encodedString), stringLen = 0;
      for (i = 0; i &lt; encodedStringLen; i++) {
          if (encodedString[i] == '%') {
              stringLen -= 1;
          } else {
              stringLen++;
          }
      }
      char *returnString = malloc(stringLen + 1), *hexValue = malloc(3);
      i = 0;
      printf("length = %d\r\n", stringLen);
      printf("+ is %d\r\n", (int)'+');
      while (encodedString[i] != '\0') {
          if (encodedString[i] == '%') {
              copyAndTerminateString(hexValue, encodedString + i + 1, 2);
              val = strtol(hexValue, NULL, 16);
              if (val != 0) {
                  returnString[n] = val;
              }
              printf("ascii \"%s\" = \"%d\"\r\n", hexValue, val);
              i += 2;
          } if (encodedString[i] == '+') {
              returnString[n] = ' ';
          } else {
              returnString[n] = encodedString[i];
          }
          i++;
          n++;
      }
      returnString[stringLen] = '\0';
      return returnString;
  }
  
  int main(int argc, char **argv) {
      char *a = "a+%2B+b+%3D%3D+13%25%21";
      char *b = urldecode(a);
      printf("String is: %s\r\n", b);
      free(b);
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>length = 13
  + is 43
  ascii "2B" = "43"
  ascii "3D" = "61"
  ascii "3D" = "61"
  ascii "25" = "37"
  ascii "21" = "33"
  String is: a B b DD 1351
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>...
  String is: a + b == 13%!
  </code></pre>