-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
49 lines (45 loc) · 977 Bytes
/
main.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#ifdef GNU_GETLINE
#define grepline getline
#else
#include "grepline.h"
#endif /*GNU_GETLINE*/
/******************************************************************************
Copyright 2013, Michael Dec
This library is licensed under 3 clause BSD license.
If it's not shipped with this software, find it yourself.
*****************************************************************************/
int main(int argc, char *argv[])
{
FILE * fp;
char * line = NULL;
size_t length = 0;
size_t read_length;
if(argc != 2)
{
puts("Please give a file");
exit(1);
}
fp = fopen(argv[1],"r");
if(fp == NULL)
{
puts("Empty file");
exit(1);
}
while(!feof(fp))
{
read_length = grepline(&line,&length,fp);
#ifdef __WIN32
printf("Read line of length %i:\n%s", read_length, line);
#else
printf("Read line of length %ld:\n%s", read_length, line);
#endif /*__WIN32*/
}
if(line)
{
free(line);
}
fclose(fp);
return 0;
}