Message from C, C++ talks

July 2019

— But it's simple

— Also I can use stack-base array.
He is using one.

— No syscalls.

— If we have a limitation to not use second array, algo will be:
1. Find space
2. Count how many spaces till non-space
3. memmove from non-space to first space position.
4. Loop 1-3 till the end of string.

Message permanent page

— 

Just for fun

#include <iostream>
#include <algorithm>

int main(int ac, char **av)
{
char str[] = "qweqweqeqw qwe qw wq eq";

std::string obj(str);
obj.erase(std::remove(std::begin(obj), std::end(obj), ' '), std::end(obj));
std::cout << obj << std::endl;
return(0);
}

— Std-cheater

— Std:: in our hearts❤️

— Now it's working for me with this func:



void removeSpaces(char *str) {
const char *n = str;
do {
while (*n == ' ') {
n++;
}
} while (*str++ = *n++);
}

Message permanent page

— If it works I like your solution

— Yep it works

— [*] Removing spaces of string: chicweawnovn edwev rer t
[+] Out string: chicweawnovnedwevrert

— It works, but he cut-off array

— Mmm what do you mean

— Last iteration of do_while loop whill set '\0', potentialy, at the mid of array

— Yea, need some fixes about last \0