i am declaring a function with void and have to call the function inside main loop and check the function as below:
void func()
{
// do something
}
int main()
{
func();
if(func()) // error here
{
//do something
}
}
but i am getting error like
error: void value not ignored as it ought to be
can anyone tell me what i made mistake..?
Well, very simple, declaring the function as "void" if you expect to act on the result of this function...
This is one of the idiocies of the C programming language. "void foo ()" is pretty much what "procedure foo ()" would be for example in Pascal. Typcasting a function as "void" simply means that there is no result value of that function, it is just a subroutine that "does something". Period.
How do you think the if-statement is to be evaluated if you explicitly declare the function not to return a value?
Ralf