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?
views:
88answers:
4
+9
A:
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;
}
}
Michael Burr
2010-01-29 00:42:36
This is the answer. Any old garbage could be in hor, pointing at any old bit of memory. Accessing that memory causes big trouble. Case closed.
Tom Smith
2010-01-29 00:44:30
Thank you very much, in hindsight ( as always) that was obvious -_-. Thanks for putting up with me.
Galileo
2010-01-29 00:45:26
+2
A:
I got the following compile errors with MSVC
error C4716: 'permute' : must return a value
warning C4700: uninitialized local variable 'hor' used
MSN
2010-01-29 00:44:14
A:
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>
thedp
2010-01-29 00:47:07