advent-of-code/2022/day08/main.c
2022-12-17 01:16:18 +01:00

37 lines
758 B
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[] )
{
FILE *file = fopen(argv[1], "r");
size_t size;
fseek(file, 0, SEEK_END); // seek to end of file
size = ftell(file); // get current file pointer
fseek(file, 0, SEEK_SET); // seek back to beginning of file
char *line = NULL;
size_t len;
ssize_t nlen;
char *forrest, *pf;
while ((nlen = getline(&line, &len, file)) != -1)
{
if (forrest == 0)
{
forrest = pf = malloc( (size / nlen) * sizeof(char*) );
int i=0;
for (; *pf != 0; pf++)
{
i++;
}
printf("%d, %zu, %zd", i, size, nlen);
}
}
}