#include string str = "a bc def"; string new_str = ""; int main() { for (int i = 0; i < length; i++) { if (str[i] == " ") i += get_spaces_num(str, i) - 1; new_str += str[i]; } return 0; } int get_spaces_num(string str, int index) { int spaces_num = 0; while (str[i++] == " ") spaces_num++; return spaces_num; }