diff options
| author | mo khan <mo@mokhan.ca> | 2015-12-30 10:55:12 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-12-30 10:55:12 -0700 |
| commit | b7de319e538ac5ede0ae51d0ac06f6462cd8da90 (patch) | |
| tree | 9d446e9cd97694d1d814491de0c91288f095c4a4 /nl.c | |
| parent | 2c3d7921d1b14e220bce11159909ecfd599d4d82 (diff) | |
implement nl.main
Diffstat (limited to 'nl.c')
| -rw-r--r-- | nl.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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; +} |
