Galileo
Galileo

Reputation: 1305

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?

Upvotes: 1

Views: 573

Answers (4)

thedp
thedp

Reputation: 8516

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>

Upvotes: 0

MSN
MSN

Reputation: 54634

I got the following compile errors with MSVC

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

Upvotes: 2

Anon.
Anon.

Reputation: 60063

hor2 = permutater[hor];

What's the value of hor?

Upvotes: 2

Michael Burr
Michael Burr

Reputation: 340516

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;
        }

}

Upvotes: 10

Related Questions