Refactored Day1/puzzle2; still needs work edition

This commit is contained in:
Benjamyn Love 2023-12-05 01:52:27 +11:00
parent f76474001b
commit fe00fd06da

View File

@ -16,137 +16,13 @@ int two_char_two_interger(int a, int b)
return num;
}
int is_one(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(3);
int is_num(char *test_string, char *num_to_match, int mem_length) {
char *input_copy = malloc(mem_length);
memcpy(input_copy, test_string, (size_t)mem_length);
memcpy(str2, str, (size_t)3);
if (strcmp(str2, "one") == 0)
{
return 0;
}
return 1;
}
int is_two(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(3);
memcpy(str2, str, (size_t)3);
if (strcmp(str2, "two") == 0)
{
return 0;
}
return 1;
}
int is_three(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(5);
memcpy(str2, str, (size_t)5);
if (strcmp(str2, "three") == 0)
{
return 0;
}
return 1;
}
int is_four(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(4);
memcpy(str2, str, (size_t)4);
if (strcmp(str2, "four") == 0)
{
return 0;
}
return 1;
}
int is_five(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(4);
memcpy(str2, str, (size_t)4);
if (strcmp(str2, "five") == 0)
{
return 0;
}
return 1;
}
int is_six(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(3);
memcpy(str2, str, (size_t)3);
if (strcmp(str2, "six") == 0)
{
return 0;
}
return 1;
}
int is_seven(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(5);
memcpy(str2, str, (size_t)5);
if (strcmp(str2, "seven") == 0)
{
return 0;
}
return 1;
}
int is_eight(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(5);
memcpy(str2, str, (size_t)5);
if (strcmp(str2, "eight") == 0)
{
return 0;
}
return 1;
}
int is_nine(char *str)
{
// printf("%c", ptr[j]);
char *str2;
str2 = (char *)malloc(4);
memcpy(str2, str, (size_t)4);
if (strcmp(str2, "nine") == 0)
{
return 0;
if (strcmp(input_copy, num_to_match) == 0) {
return 0;
}
return 1;
}
@ -197,7 +73,7 @@ int main()
switch (cur_char)
{
case 'o': // one
if (is_one(&ptr[i]) == 0)
if (is_num(&ptr[i], "one", 3) == 0)
{
if (first_num == -1)
{
@ -207,9 +83,9 @@ int main()
}
break;
case 't': // two, three
if (is_two(&ptr[i]) == 1)
if (is_num(&ptr[i], "two", 3) == 1)
{
if (is_three(&ptr[i]) == 0)
if (is_num(&ptr[i], "three", 5) == 0)
{
if (first_num == -1)
{
@ -228,9 +104,9 @@ int main()
}
break;
case 'f': // four, five
if (is_four(&ptr[i]) == 1)
if (is_num(&ptr[i], "four", 4) == 1)
{
if (is_five(&ptr[i]) == 0)
if (is_num(&ptr[i], "five", 4) == 0)
{
if (first_num == -1)
{
@ -249,9 +125,9 @@ int main()
}
break;
case 's': // six, seven
if (is_six(&ptr[i]) == 1)
if (is_num(&ptr[i], "six", 3) == 1)
{
if (is_seven(&ptr[i]) == 0)
if (is_num(&ptr[i], "seven", 5) == 0)
{
if (first_num == -1)
{
@ -270,7 +146,7 @@ int main()
}
break;
case 'e': // eight
if (is_eight(&ptr[i]) == 0)
if (is_num(&ptr[i], "eight", 5) == 0)
{
if (first_num == -1)
{
@ -280,7 +156,7 @@ int main()
}
break;
case 'n': // nine
if (is_nine(&ptr[i]) == 0)
if (is_num(&ptr[i], "nine", 4) == 0)
{
if (first_num == -1)
{
@ -342,4 +218,4 @@ int main()
close(fd);
return 0;
}
}