65 lines
1.7 KiB
C
65 lines
1.7 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <stdbool.h> //fukn c
|
||
|
|
||
|
int main() {
|
||
|
|
||
|
char zombiestring[69] = {"1000\n2000\n3000\n\n4000\n\n5000\n6000\n\n7000\n8000\n9000\n\n10000"};
|
||
|
char *zombiestringptr = zombiestring;
|
||
|
bool go = true;
|
||
|
char checker;
|
||
|
int arraypointer = 0;
|
||
|
int arraypointerbackup = 0;
|
||
|
// int newlinecount = 0;
|
||
|
int elfcount = 0;
|
||
|
int elf[69];
|
||
|
|
||
|
printf(zombiestring);
|
||
|
|
||
|
while (go == true) {
|
||
|
checker = zombiestring[arraypointer];
|
||
|
if (checker == '\0') {
|
||
|
puts("nulterminator found");
|
||
|
elf[elfcount] += atoi(zombiestringptr+arraypointerbackup);
|
||
|
printf("elf 0: %d\nelf 1: %d\nelf 2: %d\nelf 3: %d\nelf 4: %d\n\nelfcount: %d\n", elf[0], elf[1], elf[2], elf[3], elf[4], elfcount);
|
||
|
|
||
|
arraypointer = 1;
|
||
|
arraypointerbackup = 0;
|
||
|
while(arraypointer <= elfcount) {
|
||
|
if (elf[arraypointer] > elf[arraypointerbackup]) {
|
||
|
arraypointerbackup = arraypointer;
|
||
|
arraypointer++;
|
||
|
} else {
|
||
|
arraypointer++;
|
||
|
}
|
||
|
}
|
||
|
printf("the elf with the most is elf: %d with %d calories", arraypointerbackup, elf[arraypointerbackup]);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (checker == '\n') {
|
||
|
zombiestring[arraypointer] = '\0';
|
||
|
elf[elfcount] += atoi(zombiestringptr+arraypointerbackup);
|
||
|
arraypointer++;
|
||
|
|
||
|
if (zombiestring[arraypointer] == '\n') {
|
||
|
elfcount++;
|
||
|
arraypointer++;
|
||
|
}
|
||
|
|
||
|
arraypointerbackup = arraypointer;
|
||
|
|
||
|
} else {
|
||
|
arraypointer++;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
|
||
|
}
|