title: Arduino Serial Return Weird Numbers + Trouble converting char array to int C++
body: <p>I'm working on a project with this code:</p>
  
  <pre><code>#include &lt;string.h&gt;
  void setup()
  {
  Serial.begin(9600);
  }
  void loop()
  {
  
  if (Serial.available()) {
  String input = String(Serial.read());
  Serial.println("original: " + input);
  char inputarray[100];
  input.toCharArray(inputarray, 100);
    char *message = inputarray;
    char* num;
  
  
    num = strtok(message, ":");
    String numstr(num);
  Serial.println(numstr);
  
  
    num = strtok(NULL, ":");
   String numstr2(num);
  Serial.println(numstr);
  
  
  }
  
  delay(500);
  
  }
  </code></pre>
  
  <p>It's supposed to read input from the Serial port and parse it so that an input of "10:15:20" would return 3 outputs, "10", "15", and "20".</p>
  
  <p>My issue is that when I send the string "10:15:20" in the Serial terminal, it returns this:</p>
  
  <pre><code>original: 49
  49
  49
  original: 48
  48
  48
  original: 58
  58
  58
  original: 49
  49
  49
  original: 53
  53
  53
  original: 58
  58
  58
  original: 50
  50
  50
  original: 48
  48
  48
  </code></pre>
  
  <p>Now, I'm really confused. I tried entering a single number, say, '1' into the serial, and it returns this:</p>
  
  <pre><code>original: 49
  49
  49
  </code></pre>
  
  <p>So, not only does it think '1' is '49', when I enter something like "10:15:20" it loops the program 8 times while using that statement as 'input'.</p>
  
  <p>Why is this happening? Is there something wrong with my code, or is it something wrong with the arduino/arduino software?</p>
  
  <p>Any Help is greatly appreciated!!!!</p>
  
  <p>-Gabriel</p>
  
  <p><strong>EDIT: Thanks to Mitch Wheat for bringing to my attention that the serial terminal was outputting my 'numstr' variable as ASCII.... Now I'm just wondering: </p>
  
  <ol>
  <li>How do I convert char array 'num' to an int so that I can see the correct output in the Serial Monitor</li>
  <li>It doesn't seem as if I'm getting the right output in my serial monitor.... "10:15" doesn't seem to return two statements "10" and "15"...</li>
  </ol>
  
  <hr>
  
  <p>I also tried to print the output using atoi() like this:</p>
  
  <pre><code>num = strtok(message, ":");
      Serial.println(atoi(num));
  </code></pre>
  
  <p>But to no avail... (I'm not sure if I was using atoi correctly, so this may be irrelevant but I'll add it anways.
  </strong></p>
  
  <hr>
  
  <p><strong>
  BIG EDIT:</p>
  
  <p></strong></p>
  
  <p>Ok. So, thanks to Alphonsos_Pangas, I was able to get it to print correctly and verified that my strtok() was working correctly.</p>
  
  <p>Now, however, my issue is when I try to convert the string that I got from strtok(); to an int, I get an error. I've been using this code:</p>
  
  <pre><code>#include &lt;string.h&gt;
  
  String data[4];
  
  void setup()
  {
  Serial.begin(9600);
  }
  
  void loop()
  {
  
  if (Serial.available()) {
  
     String input = String(Serial.readStringUntil((char)13));
     Serial.println("original: " + input);
     //Serial.println(atoi(input.c_str()));
    // Serial.println(strtok(input.c_str(), ":"));
  
    data[0] = ((char*)strtok((char*)input.c_str(), ":"));
    Serial.println(data[0]);
  
    int testint = data[0].toInt;
  
    data[1] = (strtok(NULL, ":"));
    Serial.println(data[1]);
  
    data[2] = (strtok(NULL, ":"));
    Serial.println(data[2]);
  
    data[3] = (strtok(NULL, ":"));
    Serial.println(data[3]);
  }
  
  delay(500);
  Serial.println("end");
  }
  </code></pre>
  
  <p>It all works correctly except this line:</p>
  
  <pre><code> int testint = data[0].toInt;
  </code></pre>
  
  <p>It's supposed to convert the String (The number that I put in first) to an int, but when I try to compile it it says this:</p>
  
  <pre><code>cannot convert 'String::toInt' from type 'long int (String::)()const' to type 'int'
  </code></pre>
  
  <p>I'm not sure what I'm doing wrong...</p>