ELEC350 - Team Q / Mbed OS z_compare_commands_NEW_METHOD

Dependencies:   mbed-os

Fork of z_compare_commands by ELEC350 - Team Q

Committer:
osmith2
Date:
Thu Jan 04 23:10:03 2018 +0000
Revision:
0:f46e16e62b0c
Child:
1:81f52f1beb21
My working strcmp code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
osmith2 0:f46e16e62b0c 1 //http://www.cplusplus.com/reference/cstring/strcmp/
osmith2 0:f46e16e62b0c 2
osmith2 0:f46e16e62b0c 3 #include "mbed.h"
osmith2 0:f46e16e62b0c 4 #include <string>
osmith2 0:f46e16e62b0c 5
osmith2 0:f46e16e62b0c 6 Serial pc(USBTX, USBRX);
osmith2 0:f46e16e62b0c 7
osmith2 0:f46e16e62b0c 8
osmith2 0:f46e16e62b0c 9 DigitalOut myled(LED1);
osmith2 0:f46e16e62b0c 10
osmith2 0:f46e16e62b0c 11 //THIS CODE DOESN'T WORK YET.
osmith2 0:f46e16e62b0c 12 //This may help http://www.cplusplus.com/reference/string/string/compare/
osmith2 0:f46e16e62b0c 13
osmith2 0:f46e16e62b0c 14
osmith2 0:f46e16e62b0c 15 int main() {
osmith2 0:f46e16e62b0c 16 char key[] = "apple";
osmith2 0:f46e16e62b0c 17 char key2[] = "pear";
osmith2 0:f46e16e62b0c 18 char puttyBuffer[20];
osmith2 0:f46e16e62b0c 19
osmith2 0:f46e16e62b0c 20 while(1) {
osmith2 0:f46e16e62b0c 21
osmith2 0:f46e16e62b0c 22 myled = 1; // LED is ON
osmith2 0:f46e16e62b0c 23 wait(1.0); // 200 ms
osmith2 0:f46e16e62b0c 24 myled = 0; // LED is OFF
osmith2 0:f46e16e62b0c 25 wait(1.0); // 1 sec
osmith2 0:f46e16e62b0c 26
osmith2 0:f46e16e62b0c 27 //pc.printf("What is the password?\n");
osmith2 0:f46e16e62b0c 28 pc.printf ("Please choose a fruit?\n");
osmith2 0:f46e16e62b0c 29 fflush (stdout);
osmith2 0:f46e16e62b0c 30 scanf ("%79s",puttyBuffer);
osmith2 0:f46e16e62b0c 31
osmith2 0:f46e16e62b0c 32 if (strcmp (key,puttyBuffer) == 0){
osmith2 0:f46e16e62b0c 33 puts ("Apple is delicious!\n");
osmith2 0:f46e16e62b0c 34 }
osmith2 0:f46e16e62b0c 35 else if (strcmp (key2,puttyBuffer) == 0){
osmith2 0:f46e16e62b0c 36 puts ("Eww, pear is icky.\n");
osmith2 0:f46e16e62b0c 37 }
osmith2 0:f46e16e62b0c 38 else{
osmith2 0:f46e16e62b0c 39 puts ("try again loser!\n");
osmith2 0:f46e16e62b0c 40 }
osmith2 0:f46e16e62b0c 41 }
osmith2 0:f46e16e62b0c 42
osmith2 0:f46e16e62b0c 43 }