12 ms·
The point there is that you don’t need a buffer for whole line, you only have to find the line terminators. Something like: printf(“0: “); ln = 1;
by dfox 7y ago
The point there is that you don’t need a buffer for whole line, you only have to find the line terminators. Something like:
printf(“0: “);
ln = 1;
while ((ch = getch()) != EOF) {
putch(ch);
if (ch == EOL) {
printf(“%d: “, ln);
ln++;
}
}
And I believe that original unix implementation of nl is mostly this, although with the stdio functions replaced with raw read/write.