1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
#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);
}
}
}
|