line.c

来自「c语言库函数!里面包含了所以c语言中的系统函数的实现及其详细说明和代码!请大家及」· C语言 代码 · 共 46 行

C
46
字号
/* +++Date last modified: 05-Jul-1997 */

/*
**  LINE.C
**  Simple filter to add line-numbers to files
**
**  public domain demo by Bob Stout
**
**  Syntax:
**  LINE may be used at the end of a command-line or in the middle, e.g.
**
**  <type|cat> myfile.c | line | more
**  add line-numbers and show myfile.c one screen at a time
**
**  or 
**
**  <type|cat> myfile.c | line > lpt1
**  print listing with line numbers
**
**  or simply
**
**  line < myfile.c > file.out
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
      static unsigned long linenumber = 0;
      int ch, newline = 1;

      while (EOF != (ch = getchar()))
      {
            if (newline)
            {
                  printf("%06lu: ", ++linenumber);
                  newline = 0;
            }
            putchar(ch);
            if ('\n' == ch)
                  newline = 1;
      }
      return EXIT_SUCCESS;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?