开发者

Program unexpectedly quits for unknown reason (C++)

开发者 https://www.devze.com 2022-12-18 05:36 出处:网络
For some reason, whenever I run this program it exits at permute(permutater, length, lenth); . This doesn\'t happen whenever I comment out the line and the function doesn\'t even ru开发者_如何学Python

For some reason, whenever I run this program it exits at permute(permutater, length, lenth); . This doesn't happen whenever I comment out the line and the function doesn't even ru开发者_如何学Pythonn. Any help?


First thing I noticed - you're not initializing the index variable hor.

int permute(string permutater,int length,int lenth)
{
    int hor,hor2,marker;
    cout << length/lenth;
    for (marker=0;marker !=(length/lenth);marker++)
        {
            hor2 = permutater[hor];     // <== hor is not initialized
            permutater[hor] = permutater[hor-1];
            permutater[hor] = hor2;
            hor--;
            cout << permutater;
        }

}


hor2 = permutater[hor];

What's the value of hor?


I got the following compile errors with MSVC

error C4716: 'permute' : must return a value
warning C4700: uninitialized local variable 'hor' used


Haven't got a chance to run it yet, but did you notice that you're missing return in the permute(string permutater,int length,int lenth) function.

Also, please #include <string>

0

精彩评论

暂无评论...
验证码 换一张
取 消