There is a function:

void to_lower(char* s) { for (int i = 0; s[i] != '\0'; i++) if (s[i] >= 65 && s[i] < 90) { s[i] += 32; } } 

After the string "s [i] + = 32", it generates an error Segmentation fault.

  • Perhaps you are passing an invalid string to the function. - Vlad Sivirin
  • char * s = const_cast <char *> ("Hello, World"); to_lower (s); - Cheshire Cat
  • @CheshireCat seriously? This is a string literal! He just read them. - Andrej Levkovitch pm
  • 3
    Create an array (initialized with a literal) or just std::string . - VTT
  • one
    @CheshireCat you know how to remove a constant, but do not know how to create a string? I will support VTT, but if you need a concrete c-string, then create an array of chars. - Andrej Levkovitch

1 answer 1

 char s[] = "Hello, World"; to_lower(s);