views:

39

answers:

4
void move_paddle(PADDLE pad, bool alongX)
{
    if(alongX!=TRUE)
    {
        if((pad.py+pad.length/2)>=B || (pad.py-pad.length/2)<=BB)
            pad.pvx*= -1;
    }
    else if((pad.px+pad.length/2)>=A || (pad.py-pad.length/2)<=AA)
            pad.pvx*= -1;
}

What is the actual error ? M unable to get through.

A: 

You should use something like an int instead of a bool in c, and as long as it's value ain't 0 it's true, I would change this to

void move_paddle(PADDLE pad, int alongX)
{
    if(!alongX)
    {
        if((pad.py+pad.length/2)>=B || (pad.py-pad.length/2)<=BB)
            pad.pvx*= -1;
    }
    else if((pad.px+pad.length/2)>=A || (pad.py-pad.length/2)<=AA)
            pad.pvx*= -1;
}
Sven Almgren
also, in C, this function is useless as you don't have references and your code don't use pad as a pointer (PADDLE *pad), and you use a period (.) to access you'r structures fields...
Sven Almgren
A: 

There is no TRUE keyword in standard C language. Most probably, this is a macro declaration that you are missing. Where to get it depends on what compiler and libraries you are using. If you cannot find its definition, putting this code before the usage of TRUE (in the beginning of the file, but after all includes) will fix the problem:

#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
Vlad Lazarenko
A: 

I'm guessing that if the compiler says your error is that TRUE is not declared in this scope, then that's the actual error. Maybe you should define TRUE. Also, as I pointed out in my comment (before I had looked at the title) you're probably better off not even using TRUE in this snippet anyway. Comparing vs. TRUE in C is likely to lead to subtle errors that are hard to debug. if (!alongX) means what you wanted to say, and I find it clearer than if (alongX == FALSE).

Nathon
+1  A: 

Since you are using bool data type, looks like you are using stdbool.h in C99. If that is the case then you should change TRUE to true which expands to 1.

codaddict