aoc-2020/lib/utils.c

31 lines
584 B
C
Raw Normal View History

2020-12-12 15:59:48 +01:00
#include <stdlib.h>
#include <string.h>
#include "utils.h"
int sub_digit(char *str)
{
int ret = 0;
char *beginning = strpbrk(str, "0123456789");
int len = strspn(beginning, "0123456789");
char *tmp = (char *) malloc(sizeof(char) * len);
strncpy(tmp, beginning, len);
ret = atoi(tmp);
free(tmp);
return ret;
}
int check_ecl(char *str)
{
str = str + 1;
if (!strcmp(str, "amb") || !strcmp(str, "blu") || !strcmp(str, "brn")
|| !strcmp(str, "gry") || !strcmp(str, "grn") || !strcmp(str, "hzl")
|| !strcmp(str, "oth"))
return 1;
return 0;
}