diff options
Diffstat (limited to 'lib/hitomezashi_utils.c')
-rw-r--r-- | lib/hitomezashi_utils.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/hitomezashi_utils.c b/lib/hitomezashi_utils.c new file mode 100644 index 0000000..32832de --- /dev/null +++ b/lib/hitomezashi_utils.c @@ -0,0 +1,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; +} |