diff --git a/codereview101/snipMemory5.cpp b/codereview101/snipMemory5.cpp index 27d94fc..6ae3d91 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); - int 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; } - diff --git a/codereview101/snipMemory6.cpp b/codereview101/snipMemory6.cpp index 31698d9..6376b58 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); - int 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; }