| 1 | #include "utils.h" |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | void printarr(int a[], int n) { |
| 6 | for (int i = 0; i < n; i++) { |
| 7 | printf(COLOR_BOLD "%d " COLOR_OFF, a[i]); |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | void print_ascii(char *filename) { |
| 12 | char read_string[MAX_LEN]; |
| 13 | FILE *fptr = NULL; |
| 14 | if ((fptr = fopen(filename, "r")) == NULL) { |
| 15 | fprintf(stderr, "error opening %s\n", filename); |
| 16 | } |
| 17 | while (fgets(read_string, sizeof(read_string), fptr) != NULL) { |
| 18 | printf("%s", read_string); |
| 19 | } |
| 20 | fclose(fptr); |
| 21 | } |
| 22 | |
| 23 | void swap(int a[], int i, int j) { |
| 24 | int tmp = a[i]; |
| 25 | a[i] = a[j]; |
| 26 | a[j] = tmp; |
| 27 | } |
| 28 | |
| 29 | |
| 30 | void clearscreen(void) { |
| 31 | #ifdef _WIN32 |
| 32 | system("cls"); |
| 33 | #elif defined(unix) || defined(__unix__) || defined(__unix) || \ |
| 34 | (defined(__APPLE__) && defined(__MACH__)) |
| 35 | system("clear"); |
| 36 | #else |
| 37 | #error "OS not supported." |
| 38 | #endif |
| 39 | } |
| 40 | |