ELEC350 - Team Q / Mbed OS z_compare_commands_NEW_METHOD

Dependencies:   mbed-os

Fork of z_compare_commands by ELEC350 - Team Q

Revision:
0:f46e16e62b0c
Child:
1:81f52f1beb21
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jan 04 23:10:03 2018 +0000
@@ -0,0 +1,43 @@
+//http://www.cplusplus.com/reference/cstring/strcmp/
+
+#include "mbed.h"
+#include <string>
+
+Serial pc(USBTX, USBRX);
+
+
+DigitalOut myled(LED1);
+
+//THIS CODE DOESN'T WORK YET.
+//This may help http://www.cplusplus.com/reference/string/string/compare/
+
+
+int main() {
+        char key[] = "apple";
+        char key2[] = "pear";
+        char puttyBuffer[20];
+    
+    while(1) {
+        
+        myled = 1; // LED is ON
+        wait(1.0); // 200 ms
+        myled = 0; // LED is OFF
+        wait(1.0); // 1 sec
+        
+        //pc.printf("What is the password?\n");
+        pc.printf ("Please choose a fruit?\n");
+        fflush (stdout);
+        scanf ("%79s",puttyBuffer);        
+
+        if (strcmp (key,puttyBuffer) == 0){
+        puts ("Apple is delicious!\n");
+        }
+        else if (strcmp (key2,puttyBuffer) == 0){
+        puts ("Eww, pear is icky.\n");   
+        }
+        else{
+        puts ("try again loser!\n");
+        }
+    }
+    
+}