After i take char* variable from serial communication, i use strtok to split variables with " ". But when i do that it acts like there is " " after every character. i dont know why. How can i fix this ?
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
char* a = "The quick brown fox jumped over the lazy dog.";
char* c = a3;
char* b;
b = strtok(c, " ");
while(b != NULL){
Serial.println(b);
b = strtok(NULL, " ");
}
}
void loop() {
}
outcome :
The
quick
brown
...
this parse code works perfectly. until i take it from serialports. Serial code here. like this :
..
#include <SoftwareSerial.h>
#define bRSerial 9600
#define bRmY 9600
char vD[45];
int i = 0;
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(bRSerial);
while (!Serial) {
;
}
mySerial.begin(bRmY);
}
void loop() {
if (mySerial.available()) {
//Serial.write(mySerial.read());
vD[i]=mySerial.read();
i++;
if(i=46){
char* a = vD;
char* b;
b = strtok(a, " ");
while(b != NULL){
Serial.println(b);
b = strtok(NULL, " ");
}
i=0;
}
}
}
...outcome
T
h
e
q
u
i
c
k
b
r
o
w
...
so isthere a way to fix this ? i need to get it from serial and parse with " ". THANK YOU SO MUCH.
if ( i == 46 ) {
– Juraj May 4 '18 at 12:56c == ' '
, print vD and reset i to 0 elsevD[i] = c
– Juraj May 4 '18 at 13:17