Can I use Space as string delimiter?

im sorry before im a newbie, and i need to create some stuff for my project.

Can I use Space as string delimiter?
and then save each words to array and connect to database?

ivejun:
im sorry before im a newbie, and i need to create some stuff for my project.

Can I use Space as string delimiter?
and then save each words to array and connect to database?

yesyoucan. Youmayfinditveryhelpfulinyourendeavors.

Sure, but I would call that a word delimiter.

Go ahead.

You cannot connect to a database unless you have appropriate hardware, and you have told us nothing about your hardware.

I already has Ethernet shiled, and i want connect to PhpMyAdmin.

i need to check each word to database for preprocessing.
so i need each word to separate, and put inside array.

This My Code For Preprocessing String:

#include <string.h>

void setup() {
Serial.begin(9600);
}

void loop() {
char S = “left right up down”;
ProcessString(" ",S);
delay(1000);
}

void ProcessString(char * delimiter, char* str){
char * pch;
pch = strtok (str,delimiter);
while (pch != NULL){
Serial.print(“Pch :”);

pch = strtok (NULL, " ");
}
}

How I can put each word inside Array? then i can process to next project.

This Project i Use for Text Mining, so i need to send each word to database then check each word is available in database then database send feedback to arduino.

ivejun:
How I can put each word inside Array? then i can process to next project.

it depends…

Is your data in a fixed format/length or is is in random lengths of words and/or number of words?

BulldogLowell:
it depends…

Is your data in a fixed format/length or is is in random lengths of words and/or number of words?

i want to proccess any random word and random length.
but with maximum 5 words for each input.

For example, i use words: up down left right back

then it will save on

array0 = up
array1 = down
array2 = left
array3 = right
array4 = back

for other example i use words: left right

then it will save on
array0=left
array1= right

ivejun:
For example, i use words: up down left right back

then it will save on

array0 = up
array1 = down
array2 = left
array3 = right
array4 = back

for other example i use words: left right

then it will save on
array0=left
array1= right

that muddied the water quite a bit for me! :wink:

you could try to parse your string like this:

#define MAX_WORD_LENGTH 15

char messageArray[5][MAX_WORD_LENGTH + 1];

char message[] = "beagle boxer terrier poodle collie";

void setup()
{
  Serial.begin(9600);
  for(int i = 0; i < 5; i++)  // you can 'reset' the array by writing a null to the first element of each
  {
    messageArray[i][0] = '\0';
  }
  sscanf(message, "%s %s %s %s %s", messageArray[0], messageArray[1], messageArray[2], messageArray[3], messageArray[4]);
  for(int i = 0; i < 5; i++)
  {
      Serial.println(messageArray[i]);
  }
}

void loop()
{
  
}

BulldogLowell:
that muddied the water quite a bit for me! :wink:

you could try to parse your string like this:

#define MAX_WORD_LENGTH 15

char messageArray[5][MAX_WORD_LENGTH + 1];

char message = “beagle boxer terrier poodle collie”;

void setup()
{
  Serial.begin(9600);
  for(int i = 0; i < 5; i++)  // you can ‘reset’ the array by writing a null to the first element of each
  {
    messageArray[i][0] = ‘\0’;
  }
  sscanf(message, “%s %s %s %s %s”, messageArray[0], messageArray[1], messageArray[2], messageArray[3], messageArray[4]);
  for(int i = 0; i < 5; i++)
  {
      Serial.println(messageArray[i]);
  }
}

void loop()
{
 
}

Thanks so much

for (int i = 0; i < 5; i++)
{
//I add this code
if ( messageArray == “boxer”) {

  • Serial.println(“hello”);*
  • delay(1000);*
  • }*
    _ Serial.println(messageArray*);_
    _
    }*_
    but i still cant get hello output, how i can process each array?
    if ( messageArray[i] == "boxer") {

ivejun:
but i still cant get hello output, how i can process each array?

If I were you I would start by learning how to properly compare C strings.

functions like strcmp() or strstr().

ohh, sry i will try to send each array to database for trying. thanks so much BulldogLowell.

How i can put my Code inside loop function?

#include <SoftwareSerial.h>
#define MAX_WORD_LENGTH 15

char messageArray[5][MAX_WORD_LENGTH + 1];
SoftwareSerial BT(10, 11);
String command = "";
char message[] = "";

void setup()
{
  BT.begin(9600);
  Serial.begin(9600);

  while (BT.available()) {
    delay(10);
    char c = BT.read();
    command += c;
  }

  if (command.length() > 0) {
    Serial.println(command);
    const char* y= command.c_str();
    char message[] = {y};

    for (int i = 0; i < 5; i++) // you can 'reset' the array by writing a null to the first element of each
    {
      messageArray[i][0] = '\0';
    }

    sscanf(message, "%s %s %s %s %s", messageArray[0], messageArray[1], messageArray[2], messageArray[3], messageArray[4]);

    for (int i = 0; i < 5; i++)
    {
      Serial.println(messageArray[0]);
    }

  }

}

void loop()
{
  for (int i = 0; i < 5; i++) // you can 'reset' the array by writing a null to the first element of each
  {
    messageArray[i][0] = NULL;
  }
  command = "";
}

I have problem, Serial cant get inside char message = {y}.
thats my biggest problem now. and i want put it into loop functon.

Oke, Point of my question is, can we separate serial input, for example:

i send string text from bluetooth "hello world bro"

then arduino will recognize

array0=hello
array1=world
array2=bro

then i input other world "left down up right fly"

array0=left
array1=down
array2=up
array3=right
array4=fly

then i send each array 1 by 1, to check aviability on database. if data available, database will send a code 1 for left, code 2 for down, etc. if data unavailable database will send nothing.
just that, and that end of my project.

now i confused because i cant separate each word for send to database. that's the point of my question. hope for answer.

big thanks to someone can give me link how to do this, or give example for separate serial communication.

Hope For the answer

strtok is your friend. So are Google and Bing.

There is documentation and an example at
http://www.cplusplus.com/reference/cstring/strtok/

Good Luck!

For those who prefer a link:

http://www.cplusplus.com/reference/cstring/strtok/

(Sorry, the link button does not appear when I use my mobile device.)

In reply#3 you already use strtok to split a string. Instead of printing, send the word to the database and check the reply. Next send the next word and so on.

You also mention that the database should not reply if the word is not found. I suggest that you revise that and let the database return an invalid number (e.g. 0 or -1).

Note: the word database is used loosely.

thanks everyone i will try every suggested post. i will update my work later as soon as possible.

thanks so much