From 978462376e46bff30557bbc4a6bb79c5f5f81852 Mon Sep 17 00:00:00 2001 From: Paul Ionescu <31246137+paul-ion@users.noreply.github.com> Date: Sun, 23 Nov 2025 14:16:36 -0500 Subject: [PATCH 1/4] Update snipMemory6.cpp --- codereview101/snipMemory6.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codereview101/snipMemory6.cpp b/codereview101/snipMemory6.cpp index 31698d92..695e62a8 100644 --- a/codereview101/snipMemory6.cpp +++ b/codereview101/snipMemory6.cpp @@ -2,7 +2,7 @@ int len = 0, total = 0; while(1){ fgets(buff1, MAX_SIZE, stdin); - int len = strnlen(buff1, MAX_SIZE); + len = strnlen(buff1, MAX_SIZE); total += len; if(total < MAX_SIZE) strncat(buff2, buff1, len); else break; From bf75e40d6357ed1dd8f0b09cd8efb1f1544e8bb7 Mon Sep 17 00:00:00 2001 From: Paul Ionescu <31246137+paul-ion@users.noreply.github.com> Date: Sun, 23 Nov 2025 14:18:41 -0500 Subject: [PATCH 2/4] Fix double declaration for len --- codereview101/snipMemory5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codereview101/snipMemory5.cpp b/codereview101/snipMemory5.cpp index 27d94fcd..71ca4d24 100644 --- a/codereview101/snipMemory5.cpp +++ b/codereview101/snipMemory5.cpp @@ -2,7 +2,7 @@ int len = 0, total = 0; while(1){ fgets(buff1, MAX_SIZE, stdin); - int len = strnlen(buff1, MAX_SIZE); + len = strnlen(buff1, MAX_SIZE); total += len; if(total <= MAX_SIZE) strncat(buff2, buff1, len); else break; From f84d5941cf0eedba4166131aa655706a0fc5fce7 Mon Sep 17 00:00:00 2001 From: Paul Ionescu <31246137+paul-ion@users.noreply.github.com> Date: Sun, 23 Nov 2025 15:42:12 -0500 Subject: [PATCH 3/4] Update snipMemory6.cpp --- codereview101/snipMemory6.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/codereview101/snipMemory6.cpp b/codereview101/snipMemory6.cpp index 695e62a8..6376b589 100644 --- a/codereview101/snipMemory6.cpp +++ b/codereview101/snipMemory6.cpp @@ -1,10 +1,15 @@ -int len = 0, total = 0; +int len = 0, total = 0, CHUNK_SIZE = 16, BUFFER_SIZE = 256, chunks = 0; +char chunk[CHUNK_SIZE]; +char buffer[BUFFER_SIZE]; while(1){ - fgets(buff1, MAX_SIZE, stdin); - len = strnlen(buff1, MAX_SIZE); + fgets(chunk, CHUNK_SIZE, stdin); + len = strnlen(chunk, CHUNK_SIZE); total += len; - if(total < MAX_SIZE) strncat(buff2, buff1, len); + if(total < MAX_SIZE){ + strncat(buffer, chunk, CHUNK_SIZE); + chunks++; + } else break; } From 92bdb155d7fa5396beb181e938985a13f59ab2d6 Mon Sep 17 00:00:00 2001 From: Paul Ionescu <31246137+paul-ion@users.noreply.github.com> Date: Sun, 23 Nov 2025 15:42:39 -0500 Subject: [PATCH 4/4] Update snipMemory5.cpp --- codereview101/snipMemory5.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/codereview101/snipMemory5.cpp b/codereview101/snipMemory5.cpp index 71ca4d24..6ae3d916 100644 --- a/codereview101/snipMemory5.cpp +++ b/codereview101/snipMemory5.cpp @@ -1,10 +1,14 @@ -int len = 0, total = 0; +int len = 0, total = 0, CHUNK_SIZE = 16, BUFFER_SIZE = 256, chunks = 0; +char chunk[CHUNK_SIZE]; +char buffer[BUFFER_SIZE]; while(1){ - fgets(buff1, MAX_SIZE, stdin); - len = strnlen(buff1, MAX_SIZE); + fgets(chunk, CHUNK_SIZE, stdin); + len = strnlen(chunk, CHUNK_SIZE); total += len; - if(total <= MAX_SIZE) strncat(buff2, buff1, len); + if(total <= MAX_SIZE){ + strncat(buffer, chunk, CHUNK_SIZE); + chunks++; + } else break; } -