From 6186baa8eb541690540b856373d59c35ed1ac268 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 7 Apr 2023 11:06:00 -0700 Subject: [PATCH] Reword note about fgets() in 1992/adrian --- 1992/adrian/README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/1992/adrian/README.md b/1992/adrian/README.md index f1ad0b52c..9bc7b26f9 100644 --- a/1992/adrian/README.md +++ b/1992/adrian/README.md @@ -14,16 +14,17 @@ make all [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the location -that it used `gets()` to be `fgets()` instead to make it safer. One might think -that simply changing the gets() to fgets() (with stdin) would work but it did -not because `fgets()` stores the newline and `gets()` does not. The code was -relying on not having this newline. With `fgets()` the code `if(A(Y)) puts(Y);` -ended up printing an extra line which made the generation of some files (like -`adhead.c`) fail to compile (`gets()` does not store the newline but `fgets()` -does). Why? There was a blank line after a `\` at the end of the first line of a -macro definition! Thus the code now first trims off the last character of the -buffer read to get the same correct functionality but in a safe way. Thank you -Cody for your assistance! +that it used `gets()` to be `fgets()` instead to make it safer and to prevent +any warnings during linking or runtime. One might think that simply changing the +gets() to fgets() (with stdin) would work but it did not because `fgets()` +stores the newline and `gets()` does not. The code was relying on not having +this newline. With `fgets()` the code `if(A(Y)) puts(Y);` ended up printing an +extra line which made the generation of some files (like `adhead.c`) fail to +compile (`gets()` does not store the newline but `fgets()` does). Why? There was +a blank line after a `\` at the end of the first line of a macro definition! +Thus the code now first trims off the last character of the buffer read to get +the same correct functionality but in a safe way. Thank you Cody for your +assistance! For the original version [adrian.alt.c](adrian.alt.c) see the `Alternate code` section below.