I think you're confused somewhere. This loop condition:
for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
Ensures that i
is never greater than lim - 2
, so in the maximum-length case, i
is lim-1
after the loop exits and the null character is stored into that last position.