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; }