aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
blob: 37b50bf8ee6bb20e835554a6139f006835707471 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>

void printarr(int a[], int n) {
  for (int i = 0; i < n; i++) {
    printf(COLOR_BOLD "%d " COLOR_OFF, a[i]);
  }
}

void print_ascii(char *filename) {
  char read_string[MAX_LEN];
  FILE *fptr = NULL;
  if ((fptr = fopen(filename, "r")) == NULL) {
    fprintf(stderr, "error opening %s\n", filename);
  }
  while (fgets(read_string, sizeof(read_string), fptr) != NULL) {
    printf("%s", read_string);
  }
  fclose(fptr);
}

void swap(int a[], int i, int j) {
  int tmp = a[i];
  a[i] = a[j];
  a[j] = tmp;
}


void clearscreen(void) {
#ifdef _WIN32
    system("cls");
#elif defined(unix) || defined(__unix__) || defined(__unix) ||                 \
    (defined(__APPLE__) && defined(__MACH__))
    system("clear");
#else
#error "OS not supported."
#endif
}