Debug Assertion Failed when using pointer

Viewed 932

I am trying to understand pointers a little better and have a hard time to figure out why my code causes a debug assertion failure. When i comment out "while (*neu++ = *s++);" and comment in "strcopy(neu, s);" it works just fine. Shouldn't they do the same?

#include <iostream>
#include <cstring>

using namespace std;

void strcopy(char* ziel, const char* quelle)
{
    while (*ziel++ = *quelle++);
}

char* strdupl(const char* s)
{
    char *neu = new char[strlen(s) + 1];
    while (*neu++ = *s++);
    //strcopy(neu, s);
    return neu;
}

int main()
{
    const char *const original = "have fun";
    cout << original << endl;
    char *cpy = strdupl(original);
    cout << cpy << endl;
    delete[] cpy;

    return 0;
}
1 Answers
Related