|
1 | 1 | #include <stdbool.h>
|
2 | 2 | #include <stddef.h>
|
3 | 3 | #include <stdint.h>
|
4 |
| -#include <tice.h> |
5 |
| - |
6 |
| -#include <math.h> |
7 | 4 | #include <stdio.h>
|
8 |
| -#include <stdlib.h> |
9 |
| -#include <string.h> |
| 5 | +#include <tice.h> |
10 | 6 |
|
11 |
| -#define INPUT_SIZE 10 |
12 |
| -#define BUFFER_SIZE 20 |
| 7 | +/* Make sure to adjust those sizes according to your usage! */ |
| 8 | +#define INPUT_SIZE 10 |
| 9 | +#define RESP_SIZE 20 |
13 | 10 |
|
14 |
| -/* Function prototypes */ |
15 |
| -void print(char *text, uint8_t xpos, uint8_t ypos); |
| 11 | +/* Draw text on the homescreen at the given X/Y location */ |
| 12 | +void print(const char* text, uint8_t xpos, uint8_t ypos) { |
| 13 | + os_SetCursorPos(ypos, xpos); |
| 14 | + os_PutStrFull(text); |
| 15 | +} |
16 | 16 |
|
17 |
| -/* Main Function */ |
18 | 17 | void main(void) {
|
19 |
| - const char prompt[] = "What is N? "; |
20 |
| - char input[INPUT_SIZE]; |
21 |
| - char response[BUFFER_SIZE]; |
22 |
| - |
| 18 | + char inputBuffer[INPUT_SIZE]; |
| 19 | + char response[RESP_SIZE]; |
| 20 | + |
23 | 21 | /* Clear the homescreen */
|
24 | 22 | os_ClrHome();
|
25 |
| - |
26 |
| - /* Get an input string from the user */ |
27 |
| - os_GetStringInput(prompt, input, sizeof input); |
| 23 | + |
| 24 | + /* Ask the user to type a string, which gets stored in `inputBuf` */ |
| 25 | + os_GetStringInput("What is N? ", inputBuffer, INPUT_SIZE); |
28 | 26 |
|
29 | 27 | /* Build the user response */
|
30 |
| - strcpy(response, "N is "); |
31 |
| - strcat(response, input); |
32 |
| - |
33 |
| - /* Clear the homescreen */ |
| 28 | + sprintf(response, "N is %s.", inputBuffer); |
| 29 | + |
| 30 | + /* Clear the homescreen and display the built response */ |
34 | 31 | os_ClrHome();
|
35 |
| - |
36 |
| - /* Print the message back to the user */ |
37 | 32 | print(response, 0, 0);
|
38 |
| - |
39 |
| - /* Wait for a key press */ |
40 |
| - while (!os_GetCSC()); |
41 |
| -} |
42 | 33 |
|
43 |
| -/* Draw text on the homescreen at the given X/Y location */ |
44 |
| -void print(char *text, uint8_t xpos, uint8_t ypos) { |
45 |
| - os_SetCursorPos(ypos, xpos); |
46 |
| - os_PutStrFull(text); |
| 34 | + /* Wait for a key press before quitting */ |
| 35 | + while (!os_GetCSC()); |
47 | 36 | }
|
48 |
| - |
0 commit comments