Newbie Question.

Hi Guys!

Complete newbie here, with a quick question. I cant switch back and forth between "void FirstStage()" and "void CClient()". Any help would be greatly appreciated!!!

Many Thanks,

Googie.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<windows.h>
#include <fstream>

void FirstStage() {
	printf("First Stage!");
	Sleep(5000);
	void CCLient();
}

void CClient()
{
	printf("\n");
	printf("CCLIENT!");
	Sleep(5000);
	void FirstStage();
}

int main() {
	FirstStage();
}
Change void CCLient(); to CCLient(); and change void FirstStage(); to FirstStage();
And then wait until your program crashes because the call stack grows... and grows... and grows... and grows...
what are you trying to do, exactly?

you can alternate them just by doing so:
while(1)
{
FirstStage();
CClient();
}

but having them call each other, as said above, will not work. You can also thread them so that both are happening at the same time independently.
Hello Googie85,

What everyone has failed to notice and I will say this to the best of what I know.

Your code says it is a C program, but the include files say different.

"<fstream>" is a C++ header file for working with file streams and files. It has no knowledge of the C "printf" function. For a C program you need the header file "<stdio.h>" or for a C++ compiler "<cstdio>".

Lines 7 and 15 are very nice prototypes and do not belong there. You do not proceed a function call with a return type.

The prototypes do need to go before the function definitions especially since "FirstStage" calls "CClient" and "CClient" is not compiled before "FirstStage".

After that refer back to what MikeyBoy said and jonnin's suggestion would keep the stack from filling up, but it is still an endless loop with no way out.

Hope that helps,

Andy
Topic archived. No new replies allowed.