diff options
author | makefunstuff <[email protected]> | 2024-07-13 22:04:48 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-13 22:04:48 +0200 |
commit | 714036825c38be947eb88a82c02425d7932d2919 (patch) | |
tree | c6723bd239fa5cc93b78ef9e9b7ba5576f708db1 /csrc/wc.c | |
parent | 9b9e63476616a123eb4d00f87f677ef2d9478897 (diff) | |
download | tinkerbunk-714036825c38be947eb88a82c02425d7932d2919.tar.gz |
upd
Diffstat (limited to '')
-rw-r--r-- | csrc/wc.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/csrc/wc.c b/csrc/wc.c new file mode 100644 index 0000000..1059c5c --- /dev/null +++ b/csrc/wc.c @@ -0,0 +1,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; +} |