diff options
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..c139929 --- /dev/null +++ b/src/utils.c | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #include "utils.h" | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <time.h> | ||
| 5 | |||
| 6 | void print_line(void) { | ||
| 7 | printf("--------------------------------------------------\n"); | ||
| 8 | } | ||
| 9 | |||
| 10 | void wait_enter(const char *msg) { | ||
| 11 | if (msg) | ||
| 12 | printf("%s", msg); | ||
| 13 | int c; | ||
| 14 | while ((c = getchar()) != '\n' && c != EOF) | ||
| 15 | ; | ||
| 16 | } | ||
| 17 | |||
| 18 | char ask_yes_no(const char *msg) { | ||
| 19 | char c = 'n'; | ||
| 20 | printf("%s", msg); | ||
| 21 | if (scanf(" %c", &c) != 1) | ||
| 22 | c = 'n'; | ||
| 23 | int flush; | ||
| 24 | while ((flush = getchar()) != '\n' && flush != EOF) | ||
| 25 | ; | ||
| 26 | return c; | ||
| 27 | } | ||
| 28 | |||
| 29 | void now_str(char *buf, size_t size) { | ||
| 30 | time_t t = time(NULL); | ||
| 31 | strftime(buf, size, "%Y-%m-%d %H:%M:%S", localtime(&t)); | ||
| 32 | } | ||
| 33 | |||
| 34 | size_t rand_index(size_t max) { return max ? (size_t)(rand() % max) : 0; } | ||
