0

I have to input 5 words and organize.In order to organize words, I have to get them into Array of String to compare.I succeed to getchar[buffer] intoString in_str but somehowin_str doesn't get intostr[5].isString str[i]=in_str; Wrong?? How can I putin_str to Array ofString str??

void setup() {  Serial.begin(9600); }void loop() {  int state = 1, len = 0 ,i=0, k=1;  char buffer[128];  String str[5];  while (true) {    if (state == 1) {      Serial.print("Enter the ");      Serial.print(k);      Serial.print("th Word --> ");      state = 2;    }     while (Serial.available()) {       char data = Serial.read();      if (data == '\n') {          buffer[len] = '\0';        String in_str = buffer;        String str[i]=in_str;        Serial.println(in_str);         i=i+1;        k=k+1;        len = 0;        if(i>4){state = 3; }        else {state = 1;}         break;      }      buffer[len++] = data;    }  if(state==3){    Serial.println("After Sorting");   for (int i = 0; i < 4; i++) {    for (int j = i + 1; j < 5; j++) {      int compare = str[i].compareTo(str[j]);      if (compare > 0) {         String temp = str[i];        str[i] = str[j];        str[j] = temp;      }    }  }   for (int i = 0; i < 5; i++) {    Serial.println(String(i) + " : " + str[i]);  }    break;    }  }}
jose can u c's user avatar
jose can u c
6,9742 gold badges17 silver badges27 bronze badges
askedMar 29, 2018 at 14:28
TaeHyeong Kim's user avatar

1 Answer1

1

When you writeString str[i]=in_str; that is wrong. You only write the type when you are declaring the variable, once.

When assigning, you need only write the variable name, not the type:str[i]=in_str;

answeredMar 29, 2018 at 14:34
jose can u c's user avatar
1
  • I thought like hours to solve this problem but this was a simple mistake.. thanks for your helpCommentedMar 29, 2018 at 14:41

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.