I am reading the second edition of this great book and I have a question about a function that can be found on page 69. Here is the function:
Why, instead of writing the code highlighted in red the authors did not just write something like this?Code:int getline(char s[], int lim) { int c, i; i = 0; while (--lim > 0 && (c = getchar()) != EOF && c != '\n') s[i++] = c; if (c == '\n') s[i++] = c; s[i] = '\0'; return i; }
Thanks.Code:while (--lim > 0 && (c = getchar()) != EOF) ...