summaryrefslogtreecommitdiff
path: root/lib/hitomezashi_utils.c
blob: 32832de151b5f50a0ad3a5f0905e5da2e68f5ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "hitomezashi_utils.h"

#include <stddef.h>
#include <stdlib.h>

char *hitomezashi_ascii_binary_str_to_ints(char *ascii_str, size_t len) {
  char *res = malloc(len);
  for (int i = 0; i < len; ++i) {
    switch (ascii_str[i]) {
    case '0':;
      res[i] = 0;
      break;
    case '1':;
      res[i] = 1;
      break;
    default:;
      free(res);
      return NULL;
    }
  }
  return res;
}