ELEC350 - Team Q / Mbed OS z_compare_commands_NEW_METHOD

Dependencies:   mbed-os

Fork of z_compare_commands by ELEC350 - Team Q

main.cpp

Committer:
osmith2
Date:
2018-01-04
Revision:
0:f46e16e62b0c
Child:
1:81f52f1beb21

File content as of revision 0:f46e16e62b0c:

//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");
        }
    }
    
}