summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-03 10:13:33 +0530
committerAndinus <andinus@nand.sh>2021-09-03 10:14:20 +0530
commitd17dcc9dc41408c186543603d4d2b1bda24f218a (patch)
treefeb3307abdca3e978b061469bb0ad05a49c24f17
parent4607171bb302ba81229ed5686d7c6f546d27a33d (diff)
downloadexercism-d17dcc9dc41408c186543603d4d2b1bda24f218a.tar.gz
C: Acronym: Remove check for next character being NULL Terminator
Turns out it's not required.
-rw-r--r--c/acronym/src/acronym.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/c/acronym/src/acronym.c b/c/acronym/src/acronym.c
index 35cbfe9..9d86a6d 100644
--- a/c/acronym/src/acronym.c
+++ b/c/acronym/src/acronym.c
@@ -13,11 +13,11 @@ char *abbreviate(const char *phrase) {
         acronym[pos++] = toupper((unsigned char) phrase[0]);
 
     for (size_t idx = 0; phrase[idx] != '\0'; idx++)
-        if (phrase[idx] == ' ' || phrase[idx] == '-' || phrase[idx] == '_')
-            if (phrase[idx + 1] != '\0' && isalpha(phrase[idx + 1])) {
-                acronym = realloc(acronym, (pos + 1) * sizeof(char));
-                acronym[pos++] = toupper((unsigned char) phrase[idx + 1]);
-            }
+        if ((phrase[idx] == ' ' || phrase[idx] == '-' || phrase[idx] == '_')
+            && isalpha(phrase[idx + 1])) {
+            acronym = realloc(acronym, (pos + 1) * sizeof(char));
+            acronym[pos++] = toupper((unsigned char) phrase[idx + 1]);
+        }
 
     acronym = realloc(acronym, (pos + 1) * sizeof(char));
     acronym[pos] = '\0';