summaryrefslogtreecommitdiff
path: root/nl.c
diff options
context:
space:
mode:
Diffstat (limited to 'nl.c')
-rw-r--r--nl.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/nl.c b/nl.c
new file mode 100644
index 0000000..2af85f1
--- /dev/null
+++ b/nl.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+
+int main(int argc, const char *argv[])
+{
+ const char *filename = argv[1];
+ FILE *file = fopen(filename, "r");
+
+ if (file) {
+ int character;
+ int line_number;
+
+ printf("%6d ", ++line_number);
+ while( ( character = getc(file) ) != EOF ) {
+ putchar(character);
+ if (character == '\n') {
+ printf("%6d ", ++line_number);
+ }
+ }
+ fclose(file);
+ return 0;
+ }
+ return 1;
+}