aboutsummaryrefslogtreecommitdiff
path: root/tests/lines.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lines.c')
-rw-r--r--tests/lines.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/lines.c b/tests/lines.c
new file mode 100644
index 0000000..106491f
--- /dev/null
+++ b/tests/lines.c
@@ -0,0 +1,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.