37 lines
758 B
C
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);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|