diff --git a/3/a.out b/3/a.out new file mode 100755 index 0000000..6070101 Binary files /dev/null and b/3/a.out differ diff --git a/3/inputDemo b/3/inputDemo new file mode 100644 index 0000000..f274bda --- /dev/null +++ b/3/inputDemo @@ -0,0 +1 @@ +xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) diff --git a/3/main.c b/3/main.c new file mode 100644 index 0000000..2abd8bf --- /dev/null +++ b/3/main.c @@ -0,0 +1,35 @@ +#include +#include + +#define LINES 1000 + +int parse_numbers(char *mulString, int *a, int *b) +{ + int i = 4; + while (mulString[i] >= '0' && mulString[i] <= '9') { + *a = *a * 10 + mulString[i] - '0'; + i++; + } + i++; + while (mulString[i] >= '0' && mulString[i] <= '9') { + *b = *b * 10 + mulString[i] - '0'; + i++; + } + return 1; +} + +int main() +{ + int sum = 0; + char mulString[32]; + + FILE *input; + input = fopen("./inputDemo", "r"); + int a = 0; + int b = 0; + while (fscanf(input, "%d,%d", &a, &b)) { + sum += a * b; + } + printf("%d, %d\n", a, b); + printf("%d\n", sum); +}