简体   繁体   中英

Program unexpectedly quits for unknown reason (C++)

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 run. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM