aboutsummaryrefslogtreecommitdiff
path: root/tests/lines.c
blob: 106491ffa52cb744fd9ae6033aa38347d061ea7d (plain)
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
#include <stdio.h>

int
main (int argc, char **argv)
{
  char *progname = argv[0];
  FILE *fp;
  int c;
  unsigned count;
  
  if (argc != 2)
    {
      fprintf (stderr, "usage: %s FILE\n", progname);
      return 1;
    }

  fp = fopen (argv[1], "r");
  if (!fp)
    {
      perror (argv[1]);
      return 2;
    }

  count = 0;
  while ((c = fgetc (fp)) != EOF)
    if (c == '\n')
      count++;
  fclose (fp);
  printf ("%u\n", count);
  return 0;
}

Return to:

Send suggestions and report system problems to the System administrator.