1 /* This file is part of GNU Pies testsuite.
2    Copyright (C) 2019-2020 Sergey Poznyakoff
3 
4    GNU Pies is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8 
9    GNU Pies is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with GNU Pies.  If not, see <http://www.gnu.org/licenses/>. */
16 
17 #include <stdio.h>
18 
19 int
main(int argc,char ** argv)20 main (int argc, char **argv)
21 {
22   char *progname = argv[0];
23   FILE *fp;
24   int c;
25   unsigned count;
26 
27   if (argc != 2)
28     {
29       fprintf (stderr, "usage: %s FILE\n", progname);
30       fprintf (stderr, "Prints number of lines in FILE.\n");
31       return 1;
32     }
33 
34   fp = fopen (argv[1], "r");
35   if (!fp)
36     {
37       perror (argv[1]);
38       return 2;
39     }
40 
41   count = 0;
42   while ((c = fgetc (fp)) != EOF)
43     if (c == '\n')
44       count++;
45   fclose (fp);
46   printf ("%u\n", count);
47   return 0;
48 }
49