fscanf wont work. will have to map the file to an array and parse it manually.

This commit is contained in:
kirreen 2024-12-03 15:35:07 +01:00
parent aa5470f8e1
commit 0f12df574f
3 changed files with 36 additions and 0 deletions

BIN
3/a.out Executable file

Binary file not shown.

1
3/inputDemo Normal file
View file

@ -0,0 +1 @@
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))

35
3/main.c Normal file
View file

@ -0,0 +1,35 @@
#include <stdlib.h>
#include <stdio.h>
#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);
}