[Solved] Understand a C program


What the code does is fetch one character from the input stream at a time, and then store the character at the ith position in the s array, then it increments i.

It tests for two conditions, if i == lim - 1 then the loop ends, and the '\0' is appended at the lim position in the array, if a '\n' was encounterd or the EOF end of file was reached, then the loop also ends.

In case the last character read was '\n' then it’s appended at the ith position, and i is incremented, and then a '\0' is appended at new ith position.

If not, then just append '\0' at the ith position, and return.

No character will be read until the Enter key is pressed, so the loop will actually start running after the moment Enter is pressed, and the algorithm will do what I describe.

3

solved Understand a C program