home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / LINE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  945b  |  46 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  LINE.C
  5. **  Simple filter to add line-numbers to files
  6. **
  7. **  public domain demo by Bob Stout
  8. **
  9. **  Syntax:
  10. **  LINE may be used at the end of a command-line or in the middle, e.g.
  11. **
  12. **  <type|cat> myfile.c | line | more
  13. **  add line-numbers and show myfile.c one screen at a time
  14. **
  15. **  or 
  16. **
  17. **  <type|cat> myfile.c | line > lpt1
  18. **  print listing with line numbers
  19. **
  20. **  or simply
  21. **
  22. **  line < myfile.c > file.out
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27.  
  28. int main()
  29. {
  30.       static unsigned long linenumber = 0;
  31.       int ch, newline = 1;
  32.  
  33.       while (EOF != (ch = getchar()))
  34.       {
  35.             if (newline)
  36.             {
  37.                   printf("%06lu: ", ++linenumber);
  38.                   newline = 0;
  39.             }
  40.             putchar(ch);
  41.             if ('\n' == ch)
  42.                   newline = 1;
  43.       }
  44.       return EXIT_SUCCESS;
  45. }
  46.