From d17dcc9dc41408c186543603d4d2b1bda24f218a Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 3 Sep 2021 10:13:33 +0530 Subject: C: Acronym: Remove check for next character being NULL Terminator Turns out it's not required. --- c/acronym/src/acronym.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'c/acronym') 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'; -- cgit 1.4.1-2-gfad0