Count the lines
Count the lines and the bytes on standard input without scanf or getchar: ask the operating system for the bytes yourself with the read system call. With the stdin box as given the program prints lines: 3, bytes: 34.
read is service 63. Put the file descriptor, the number that names an open file, in x0 (0 is standard input), the buffer address in x1, the most bytes you want in x2, and 63 in x8, then run svc 0. The answer in x0 is how many bytes actually arrived, which can be fewer than you asked for. An answer of 0 means the input is finished.
So read into the 64-byte buf in a loop: add each answer to the byte count, and count the newline bytes (value 10) among the bytes that read just delivered. Only those: whatever sits past them in buf is left over from an earlier read. A line counts when its newline arrives, so text whose last line has no newline has one line fewer than it looks.
The stdin box stands in for running the program with < file on a server: once its text runs out, read answers 0. If a run ever sits waiting for more input instead, Ctrl-D in the console's input line ends it.
What is checked
- the count line for the text in the stdin box, and for more inputs you cannot see (short, empty, and longer than the buffer)
- the program exits cleanly
- the input comes through system calls (
svcpresent, nogetchar)
specification
svcscanf or getcharWe run your program on the input above and on the hidden ones, and compare what it does. Nothing is matched against a stored solution.