main.c (758B)
1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <string.h> 4 5 int main(int argc, char *argv[] ) 6 { 7 FILE *file = fopen(argv[1], "r"); 8 size_t size; 9 10 fseek(file, 0, SEEK_END); // seek to end of file 11 size = ftell(file); // get current file pointer 12 fseek(file, 0, SEEK_SET); // seek back to beginning of file 13 14 char *line = NULL; 15 size_t len; 16 ssize_t nlen; 17 char *forrest, *pf; 18 19 while ((nlen = getline(&line, &len, file)) != -1) 20 { 21 if (forrest == 0) 22 { 23 forrest = pf = malloc( (size / nlen) * sizeof(char*) ); 24 int i=0; 25 for (; *pf != 0; pf++) 26 { 27 i++; 28 } 29 printf("%d, %zu, %zd", i, size, nlen); 30 } 31 32 } 33 34 35 } 36