I am new to using pointers (and Visual Studio too) and I'm trying to make a function which deletes the spaces ' ' from a const array. The function should return another array but without the spaces. Seems pretty simple, the code works in Codeblocks, but in Visual Studio it keeps triggering breakpoints. Any idea what am I doing wrong?
char* removeSpaces(const char* text) {
int length = strlen(text);
char* clone = new char(strlen(text));
strcpy_s(clone,length+1, text);
int i = 0;
do {
if (clone[i] == ' ')
strcpy(clone + i, clone + i + 1);
i++;
} while (i < length);
return clone;
}