#include #include #include int main(int argc, char* argv[]) { FILE* f = NULL; size_t size = 0; char* line = NULL; ssize_t nread = 0; unsigned long long bat_sum = 0; f = fopen(argv[1], "r"); while ((nread = getline(&line, &size, f)) != -1) { unsigned long long bat_n = 0; int number_of_batteris = 12; int b_i = 0; int a_i_1 = 0; int a_i = -1; int b = 0; printf("line: %s",line); // go through each line (we can keep as chars) get the largest number, get its index, // go through second loop starting from that index, get the largest number there. // i love loops within loops //generalizing for n amount of battteris for (int n = number_of_batteris; n>0; n--) { a_i_1 = a_i; a_i = 0; int a = 0; for (int i = a_i_1+1; i< nread-1-n+1; i++) { // we dont need line end char i think., and we cant choose the last one since then there will be no place for the second battery if (a < line[i] - '0') { a_i = i; a = line[i] - '0'; } } bat_n = bat_n*10; bat_n += a; } printf("digits :(%llu)\n\n",bat_n); bat_sum += bat_n; } printf("bat summ: %llu\n",bat_sum); free(f); free(line); return 0; }