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-05
Revision:
1:81f52f1beb21
Parent:
0:f46e16e62b0c
Child:
2:690dd6bdb9a7

File content as of revision 1:81f52f1beb21:

//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];
        char numBuffer[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);
        //scanf ("%79s",numBuffer);

        if (strcmp (key,puttyBuffer) == 0){
        puts ("Apple is delicious!\n");
        /*
        pc.printf ("The command entered is %u characters long.\n",(unsigned)strlen(key));
        int i =0;
        int keysize = (unsigned)strlen(key);
        int endfor = keysize;
        
        //check for number here
        
        for(i=0; i<endfor; i++)
            {
            pc.printf("%c", puttyBuffer[i]);
            }
        */
        }
        else if (strcmp (key2,puttyBuffer) == 0){
        puts ("Eww, pear is icky.\n");   
        }
        else{
        puts ("try again loser!\n");
        }
    }
    
}