number.c
来自「c和指针的配书源码」· C语言 代码 · 共 42 行
C
42 行
/*
** Copy the standard input to the standard output, and number the
** output lines.
*/
#include <stdio.h>
#include <stdlib.h>
int
main()
{
int ch;
int line;
int at_beginning;
line = 0;
at_beginning = 1;
/*
** Read characters and process them one by one.
*/
while( (ch = getchar()) != EOF ){
/*
** If we're at the beginning of a line, print the
** line number.
*/
if( at_beginning == 1 ){
at_beginning = 0;
line += 1;
printf( "%d ", line );
}
/*
** Print the character, and check for end of line.
*/
putchar( ch );
if( ch == '\n' )
at_beginning = 1;
}
return EXIT_SUCCESS;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?