The array code is wrong or the comparasion?

This is the code:

String string = ""; char* gender[]={"male", "female"};

void setup() { // put your setup code here, to run once: Serial.begin(9600); }

void loop() { // put your main code here, to run repeatedly: if( Serial.available() ) {

string = Serial.read(); }

if( string == gender[0] ){

Serial.print(gender[0]); delay(50); } else if( string == gender[1] ){

Serial.print(gender[1]); delay(50);

}

}

It is supposed to print malewhen i type male in the serial monitor and print female when i type female. What is exactly the problem???

It is supposed to print malewhen i type male in the serial monitor

When you type "male" in the serial monitor, and press send, what the Arduino gets is 'm', 'a', 'l', 'e', with many, many iterations of loop() happening before the first character arrives and between each character arriving.

You are reading one int at a time, pissing away resources using the String class, storing that int in a String.

'm' != "male" despite any amount of wishful thinking.

http://forum.arduino.cc/index.php?topic=396450.0

Thanks, but i want to use whole words instead of single letter.

JMD1: Thanks, but i want to use whole words instead of single letter.

So, if you use the techniques in the link I posted, you can collect all the letters into an array, until the carriage return or line feed arrives (assuming that you set the Serial Monitor app to append one or the other, or both). When the carriage return or line feed arrives, use strcmp() to compare the strings.

Ok but how should the code be changed? Can you please post the code already modified?

We don't do that. There's a section called "Gigs and Collaborations" where you can hire someone to just write it for you. Expect to pay for that service.

Read that thread he linked you to until you understand it. Any terms you don't get go google them. This isn't magic and it really isn't that hard. You just have to stop looking for instant gratification and spend some time thinking.