E
E
EmachinesDIMA2018-10-23 11:03:05
C++ / C#
EmachinesDIMA, 2018-10-23 11:03:05

How to formulate the cycle correctly so that it stops checking “this is a number” when it is already followed by a letter?

for (pch = s1; *pch; ++pch) {
    if (isalpha(*pch))
      *pch = islower(s1[0]) ? tolower(*pch) : toupper(*pch); // ternary operator
    else if (isdigit(*pch)) {
      while (isdigit(*pch) && isalpha(*pch++))
        pch++;
    }

Let's say the original string:
7ello, World!!111oneONEone
and to be
7ello, world!!111oneoneone
and not
7eLLO, WORLD!!111oNEONEONE

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EmachinesDIMA, 2018-10-23
@EmachinesDIMA

https://pastebin.com/4rrDRWgw

char *pch;
  for (pch = s1; *pch; pch++) {
    if (isalpha(*pch)) {
      if (isupper(s1[0]))
        *pch = toupper(*pch);
      else
        *pch =  tolower(*pch) ;
    }
    else continue;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question