If a word contains an odd number of characters,you must replace the middle letter of the word use this sumbol "*" | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

If a word contains an odd number of characters,you must replace the middle letter of the word use this sumbol "*"

HelpšŸ˜Š

22nd Feb 2017, 6:12 PM
Vanja Pin
Vanja Pin - avatar
2 Respostas
+ 11
#include <cstring> and use strlen() function to check the length of the string. If char count is odd, replace mid of string with * using half char count obtained by strlen(). E.g. string text = "SoloLearn"; int count = strlen(text.c_str()); if (count%2 != 0) { text[count/2] = '*'; }
22nd Feb 2017, 6:18 PM
Hatsy Rei
Hatsy Rei - avatar
22nd Feb 2017, 6:37 PM
Akshata
Akshata - avatar