Use a Scanner to read user input from the terminal and gather basic data about the user.
cmake_minimum_required(VERSION 3.3)
project(Scanner_Demo C CXX ASM)
create_simple_executable(${PROJECT_NAME} Scanner_Demo.cpp)
bool isAnswerNo (char const userInput[]);
void error (const PropWare::ErrorCode err);
char userInput[64];
char name[64];
unsigned int age;
pwOut.
printf(
"Hello! I'd like to teach you how to use PropWare to read from the terminal!\n");
do {
pwOut <<
"First, what's your name?\n>>> ";
pwIn.
gets(userInput,
sizeof(userInput));
strcpy(name, userInput);
pwOut <<
"And how old are you?\n>>> ";
pwIn >> age;
pwOut <<
"Is your name " << name <<
" and are you " << age <<
" years old?\n>>> ";
pwIn.
input_prompt(
"",
"Please enter either 'yes' or 'no' (y/n)\n>>> ", userInput,
sizeof(userInput),
} while (isAnswerNo(userInput));
return 0;
}
bool isAnswerNo (char const userInput[]) {
return 0 == strcmp("n", userInput) || 0 == strcmp("no", userInput);
}
void error (const PropWare::ErrorCode err) {
while (1) {
debugLEDs.write((uint32_t) err);
waitcnt(100 * MILLISECOND);
debugLEDs.write(0);
waitcnt(100 * MILLISECOND);
}
}