about summary refs log tree commit diff
path: root/csrc/wc.c
blob: 1059c5c5ff9360ac5e259f13f89f01d5aef3857b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "wc.h"
#include <stdio.h>

int count_lines(char *src) {
  FILE *file = fopen(src, "r");

  if (file == NULL) {
    return -1;
  }

  int lines = 0;
  char c;
  while ((c = fgetc(file)) != EOF) {
    if (c == '\n') {
      lines++;
    }
  }
  fclose(file);
  return lines;
}