N00B here. I need to reuse a function's return in other functions. The problem is that the function's return changes every time it is called. How to achieve this?

int FUNCTION1(void)
{
	// do stuff

	return FUNCTIONRESULT; // return to be reused in other functions
}

int FUNCTION2(void) // <- this must be void
{
	// do stuff
	int NUMBER = FUNCTION1(); // FUNCTION1's return is reused here but it is not the same value as in FUNCTION3

	return WHATEVER;
}

int FUNCTION3(void) // <- this must be void
{
	// do stuff
	int NUMBER = FUNCTION1(); // FUNCTION1's return is reused here but it is not the same value as in FUNCTION2

	return WHATEVER;
}

Recommended Answers

All 3 Replies

line #11: u are calling fun1 and expecting the ret val of fun3
line #19: u are calling fun1 and expecting the ret val of fun2

Member Avatar for manutm

use global variables

Why must the function calls be void-ed?
Aside from global variables ... there isn't a direct way of doing it really.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.