<Post moved from dead thread>
is it possbile if the string letters can be alternatively capital?
like uhmm ex. boring to a bOrInG? and without using the any str?

Dani AI

Generated

As already confirmed, alternating letter case is straightforward. Below are two practical patterns (alternate every character vs. alternate only letters) with ready-to-use C and JavaScript examples, plus a few caveats that address common pitfalls raised in threads like this one (for example handling punctuation or non-ASCII text).

C (skips non-letters, caller frees result):

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

char *alternate_case_letters(const char *s)
{
    size_t n = strlen(s);
    char *out = malloc(n + 1);
    if (!out) return NULL;
    int make_upper = 0; /* start lowercase for first letter */
    for (size_t i = 0; i < n; ++i) {
        unsigned char ch = (unsigned char)s[i];
        if (isalpha(ch)) {
            out[i] = make_upper ? toupper(ch) : tolower(ch);
            make_upper = !make_upper;
        } else {
            out[i] = s[i];
        }
    }
    out[n] = '\0';
    return out;
}

JavaScript (ASCII letters by default; optional Unicode support noted after):

function alternateCaseLetters(str, skipNonLetters = true) {
  if (skipNonLetters) {
    let i = 0;
    return str.replace(/[A-Za-z]/g, ch => (i++ % 2 ? ch.toUpperCase() : ch.toLowerCase()));
  } else {
    return str.split('').map((c, idx) => idx % 2 ? c.toUpperCase() : c.toLowerCase()).join('');
  }
}

/* Example:
   alternateCaseLetters("boring") -> "bOrInG"
*/

Notes and caveats:

  • In C, always cast to unsigned char before calling isalpha/toupper/tolower to avoid undefined behavior. For UTF-8 input in C, these routines operate on bytes; use wide-char functions or a library like ICU for true Unicode case mapping.
  • In JS, toUpperCase()/toLowerCase() work with Unicode, but matching letters with /[A-Za-z]/ is ASCII-only. Use /\p{L}/gu (ES2018+) to match Unicode letters, and toLocaleUpperCase() for locale-specific rules (Turkish i).
  • If the original intent was "no string functions", an ASCII-only manual test (compare ranges 'a'..'z'/'A'..'Z' and adjust codes) will work but is limited and less robust than standard APIs.

This addresses the basic use case shown by and gives safe, extendable code for production use.

Recommended Answers

All 2 Replies

>>is it possbile
Yes

thanx... anyway i got the solution to that..... :D take care

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.