From ac44647809284e2ac94f0937be4c22e7d0458fe0 Mon Sep 17 00:00:00 2001 From: Muhammad Salah <67175615+MuhammadSalah-MS@users.noreply.github.com> Date: Tue, 15 Apr 2025 20:36:32 +0200 Subject: [PATCH] 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 --- chapter_1/exercise_1_16/longest_line.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chapter_1/exercise_1_16/longest_line.c b/chapter_1/exercise_1_16/longest_line.c index f102ff1..3516e62 100644 --- a/chapter_1/exercise_1_16/longest_line.c +++ b/chapter_1/exercise_1_16/longest_line.c @@ -54,6 +54,10 @@ int get_line(char line[], int maxline) ++i; c = getchar(); } + + if (c == '\n') + ++i; + return i; }