Skip to content

Commit ac44647

Browse files
Fix: Correctly count length of longer lines when including newline escape sequence '\n'
The previous version of get_line did not increment the length counter for the final newline character when the line exceeded MAXLINE. This commit adds a check after counting the extra characters before EOF and '\n' Incrementing the counter if there was an escape sequence for newline
1 parent e905fdd commit ac44647

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

chapter_1/exercise_1_16/longest_line.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ int get_line(char line[], int maxline)
5454
++i;
5555
c = getchar();
5656
}
57+
58+
if (c == '\n')
59+
++i;
60+
5761
return i;
5862
}
5963

0 commit comments

Comments
 (0)