|
jiuyejii wrote: what's the problem of my code?? can't create the maze. may be problem comes from back to previous step,but how to correct it? You seriously need to learn to use the debugger to help solve such problems. Dumping a boatload of code in a forum and asking others to wade through it will get you nowhere.
Instead of trying to solve the problem as a whole, break it down into smaller chunks. If stack space is being exhausted, you most likely have a recursion problem.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
did you debug with a small maze size?
do you check array boundaries ? (for example in function count ).
You should try to convert the recursion to a iterative (loop); it might help fix the stack overflow.
Watched code never compiles.
|
|
|
|
|
No idea what's causing your stack overflow, but as one of the previous posters mentioned (think it was David, sorry if I've got that wrong) it's probably related to recursion.
As to what the problem is with your code I can sum that up in one word. Abstraction. There's not a lot is there? When you write huge lumps of code how are other people meant to follow what you mean? Come to think of it how are you supposed to be able to follow it next week? And if you and other people are having problems think of the poor, literal minded compiler, he's having a nightmare [1].
So even if you don't want to do the whole OO thing, think about splitting your code up into nice little packets you and the rest of the world can understand. Here are some guidelines which have served me well:
- make each function only do one thing but make it do it well
- split loops and complex conditionals out into their own functions
- if a variable name is only a couple of characters long it's almost always too short
- if you've got more than 2 levels of indirection in an expression then that's too much. If you've got 2 it's probably still too much. Things like char **& are right out
- even if you're programming in "C like" C++ don't play about with memory directly. Let someone else do the heavy lifting. std::vector, std::unique_ptr and std::shared_ptr can cover about 99% of your dynamic memory requirements.
Interestingly you've got one complex conditional in it's own function. Cool! Keep that up and look for other places you can do the same sort of thing. FREX you've got the following segment of code:
c--;
i=cti[c];
j=ctj[c];
cti[c+1]=0;
ctj[c+1]=0; in four places. Think of a name to describe what this lot is up to and pack it away in a function. Do that a few more times and you might be starting to see where your code is going wrong.
[1] I've committed a cardinal sin here, I've anthropomorphised a computer. They don't like it when you do that.
|
|
|
|
|
Aescleal wrote: I've anthropomorphised a computer. They don't like it when you do that. No wonder OP has a stack overflow, with recursion like that!
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thank you for your advice
|
|
|
|
|
|
The problem is right at the end of the function cmaze() : there you call the same function, recursively. That means for every step, your program will push one more function call on the stack, and it won't resolve it until the very end.
Don't do that kind of thing. Instead use the return code to indicate whetehr or not you need to do another step, and create a loop:
Change the function cmaze to:
bool cmaze(int& i, int& j) {
if (maze[out][N]=='.')
return false;
return true;
}
Change your call to cmaze in makebg() to:
i = in;
j = 1;
while (cmaze(i, j));
|
|
|
|
|
You are right and your suggestions let me learn more,thanks
|
|
|
|
|
i took an MFC application written in VS2010
opened in in win8 with visual studio 2012
got the following errors:
error C1083: Cannot open include file: "tmschema.h": No such file or directory (afxwin.h)
it returns in several cases
anyway can help?
thanks
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
YaronNir wrote: anyway can help?
Does tmschema.h exist?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
actually you are right, it doesn't
will check more
thanks
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
|
The include file "tmschema.h" is part of the Microsoft SDK (in v6.0 and v7.0), and is included by Visual Studio 2010 (in afxwin.h). However, Visual Studio 2012 doesn't appear to have the correct include files and/or libraries.
I'm looking to see if there's a known solution, and I'll post here again when I've worked it out!
|
|
|
|
|
hello guys... I have these two track bars on my form. Now even though I check which tracked bar was clicked; it still executes the code twice which is very awkward. Here is what I am trying
void CMainDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if((CSliderCtrl*)pScrollBar == &m_trackONE)
{
}
if((CSliderCtrl*)pScrollBar == &m_trackTWO)
{
}
}
It correctly recognizes which track bar I clicked but why does it starts executing all over again? thanks for any pointer.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
does nSBCode change between calls?
|
|
|
|
|
Thanks for ur time. It does change. For both track bars I checked this and both times
- on first call nSBCode had a value of 3
- on second call nSBCode had a value of 8
This world is going to explode due to international politics, SOON.
|
|
|
|
|
3 = SB_PAGERIGHT
8 = SB_ENDSCROLL
so, it's telling you two different things
|
|
|
|
|
Chris Losinger wrote: so, it's telling you two different things
Well I am afraid I don't know its meaning. What should I do? Should I be worried or something?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
SB_ENDSCROLL just means the user has let go of the mouse button and is no longer interacting with the control, so scrolling is done. you can probably ignore it.
|
|
|
|
|
Overloaded_Name wrote: Well I am afraid I don't know its meaning. What should I do? Should I be worried or something?
Probably you should have a look at this[^]!
|
|
|
|
|
Since pScrollBar can't point to two controls at the same time during the same call to OnHScroll() , the second if() statement should have an else in front of it.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
We have a utility that needs to maximize resources. We stop indexing by stopping the wsearch service. But within a matter of minutes it restarts. I thought there might be a connection to Outlook but even with outlook not started this happens.
We would rather not set the service to disabled. If anyone has any information or suggestions it is appreciated.
Thanks, kc
In the event log i see these two messages associated with the indexing restart.
Event 102, ESENT
Windows (6604) Windows: The database engine (6.01.7601.0000) started a new instance (0).
and
Event 1003, Serach
The Windows Search Service started.
--------------------------------------------------------------------------------
|
|
|
|
|
Before I start, I'll admit to feeling dirty for even considering such an approach..
However, it sounds very much like the service has a watch-dog application monitoring it. Once the monitoring app detects that it is no longer running, it simply restarts the service.
If this is the case, you may be able to fool the watch-dog app. Often this type of arrangement has a Mutex at it's heart. The service creates a mutex, the watch-dog then tries periodically to create a mutex with the same name. If the operation fails, the service is still running as per normal. If on the other hand, the mutex creation is successful, one can safely assume that the intended creator of the mutex (the service) has ceased running and taken the mutex with it.
On second thoughts, scratch that idea - it's a service that comes bundled with Windows. It seems likely that Windows itself maintains an in-memory list of services and their current state.
On third thoughts, I can't think of a way of doing this (other than with the standard Services dialogs) that couldn't reasonably be considered a hack. Nonetheless,
I just read a thread in which one writer spoke of having to change the permissions on some registry key(s?) in order to change the service startup type...
Last post here.[^]
I guess that leaves you an avenue of investigation:
- Change the reg-key to indicate Disabled, kill the service. Once proessing done, set Automatic (Delayed Start) then let windows start the service up when 'needed'.
No idea which RegKey though..
|
|
|
|
|
Is this a C/C++/MFC question is disguise?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Wolfkc wrote: We would rather not set the service to disabled.
I don't understand that.
You "disable" the service by stopping it or pausing it (if it allows that.)
You have a process that runs for X amount of time. I presume that you want to insure that the service is not running for that amount of time. And presumably after your process completes then you want to allow the service to continue to run.
So your options are to "disable" the service or reconfigure it to insure that it doesn't run. The first is more certain to succeed and less complex. Reconfiguring it is not certain because at best you can only insure that it will not be running at some future time. And in both cases you must restore it to the correct running state.
|
|
|
|