LINE -- Line Number Pipe 
Author Message
 LINE -- Line Number Pipe




Newsgroups: comp.lang.c
Organization: Human Excellence Center (Lahore, Pakistan)

This is the source code showing the implementation of pipes on
MS-DOS.

------------------LINE.C starts-----------------------------

/*
 LINE.C
 Simple MS-DOS pipe to add line-numbers to files
 (c) Masud Reza, 1995

 Tested and comiled using Turbo C 2.0 and the Turbo De{*filter*}
 MAXLINE is set at 1000 which is enough for most files.

 LINE may be used at the end of a command-line or in the
 middle.
 e.g.

 type myfile.c | line | more
 add line-numbers and show myfile.c one screen at a time

 or

 type myfile.c | line > lpt1:
 print listing with line numbers on screen

*/

#include <stdio.h>

#define MAXLINE 1000  /* max. number of chars in a line */

char inputline [MAXLINE];  /* line read from stdin  */
char outputline[MAXLINE];  /* line to be written to stdout */

short main ( void )
{

static unsigned long linenumber;

 /* while there's a line in the input-line, read it, add a line-number
    and write the line back to stdout
 */

 while ( fgets( inputline, MAXLINE, stdin ) )
  {
   ++linenumber;
   vsprintf( outputline, "%lu: ", &linenumber );
   strcat( outputline, inputline );
   fputs( outputline, stdout );
  }

 return 0;

Quote:
}

----------------------LINE.C ends------------------------------

          +
      **      **  
     * *    * *    +
 +  *  *  *  *  
   *   **   *         +
| *    *   *   A  S  U  D|

---
 * QNet3B * ILink: 786BBS * Karachi, Pakistan  * 0092-21-722-5355



Sun, 16 Nov 1997 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. LINE -- Line Number Pipe for MS-DOS

2. Command line stdin versus piped in?

3. Processing lines received through a pipe

4. Return Line without pipe symbol

5. Printing line-by-line

6. Reading from a text file line by line

7. Opening a text file/Displaying text line by line

8. Multi-Line Comments Nested in Single Line Comments

9. char *line vs. char line[]

10. Reading Line per line in C

11. Dispaly lines of Lines of file with Win 3.1 SDK

12. Printing a text line on a printer line

 

 
Powered by phpBB® Forum Software