9p / who / tweedy / 9C / 1


Count Lines

Code

#include <u.h>
#include <libc.h>
#include <bio.h>

#define STDIN   0

/* count lines in input */

void
main()
{
    Biobuf *bstdin;
    bstdin = Bfdopen(STDIN, OREAD); 
    int c, nl;

    nl = 0;
    while((c = Bgetc(bstdin)) >= 0)
        if(c == '\n')
            ++nl;
    print("%ud \n", nl);

    exits(0);
}

Output

$ 9c lines.c; 9l lines.o -o lines
$ ./lines 
how
many  
lines?
3 



tweedy