is there a way to print out the line number in C while only using putchar
and getchar
and no arrays?
the output should look like this.
for example input mink
01: mink
02: jaguar
and so on
The line number should go from 01
to 50
.
This is my start approach
#include <stdio.h>
int main() {
int c;
int counter = 1;
while ((c = getchar()) != EOF) {
putchar(c);
if (c == '\n') {
putchar(counter + '0');
putchar(':');
putchar(' ');
++counter;
}
}
return 0;
}