Unkown Syntax error.

So I've been making a decently large single file program to simulate The Game of Life, and I think I have everything ready but for some reason im getting stuck in an infinite loop in a situation where the variable getting changed *shouldn't* be changed or atleast I certainly dont want it to be changed, the thing that's confusing to me is that the code run's fine (straight into an infinite loop mind you) but the debugger warns me of a syntax error near my if statement that compares a value within a char array with another char, when I watched the variables, one of the variables that denotes the position of the char within the array gets changed somehow during or after the if statement and I can't find any reason why it would happen and im very frustrated. Im going to give you the function itself (because the whole program is rather large) and try to explain the variables best as I can.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  void nextGen(bool che[][SIZEY],char dis[][SIZEY],int SIZEX)
{
    bool temp[8];
    int l,p;

    for(int k=0;k<7;k++)
    {
        temp[k]=false;
    }


    for(int i=0;i<SIZEY;i++)
    {
        p=i;
        for(int j=0; j<SIZEX;j++)
        {
            l=j;

            createPoint(dis,SIZEX,temp,j,i);

            if (dis[l][p] == '*')
            {
                checkPointA(che,SIZEX,temp,j,i);
            }
            else
            {
                checkPointD(che,SIZEX,temp,j,i);
            }

        }
    }
}


When the if statement executes l changes from whatever it was to a value of 0 and even sometimes 1 (which further confuses me).

To clarify the three functions within this function work correctly (I've checked them in the debugger) the problem is at the if statement (I originally didn't use l and p because they are redundant but it made tracking the unintended change easier for me).

Any help is vastly appreciated ( and yes I know there are no comments ), also this assignment is for a class so using certain things that might make this whole process easier are forbidden for me to use (I cant even use explicit pointers).
Last edited on
1
2
3
4
5
bool temp[8];
for(int k=0;k<7;k++)
{
    temp[k]=false;
}

You are leaving value of temp[7] uninitialized. It may be the reason.
Last edited on
You make a very good point, thank you changed it. ( I guess my head crossed wires when it was thinking that the array went up to 7 from 0 ).
Still need help please, Initializing all of the temp values did not fix it.
Last edited on
One thing to note - you are passing the same (not copy of) array temp[] each time the loop passes. If any of the elements of this array is changed in createPoint(), it stays that way for the next passing through the loop. I do not know if this function changes any of the values, but then, if it is not - why the hell bother with passing 8 elements, if we know they all start at value false.

Consider reinitializing temp[]inside the loop, not before.
Also - and I know it's far-fetched - but do the functions inside the loop take i and j by value, or maybe by reference (invocation would look the same, but behaviour would change drastically).
Last edited on
The functions take them by value, and again you're right about temp[] it should be initialized inside the loop, but im still unfortunately stuck inside an infinite loop and it has something to do with if (dis[l][p] == '*'). No error appears in the compilation of the program, but the debugger claims there is a syntax error "near" the if statement, and everytime the loop hits that statement "l" get's changed from whatever it was depending on the number of times the loop has passed to 0 or 1. The only reason it ever goes above 0 and 1 is because I reassign it to "j" each time. I don't understand why an if statement is changing a variable used to indicate a place within the array that is being compared.. how does that even happen? Am I missing some rule that relates back to C or something?

I appreciate all the help.
Last edited on
I figured it out!! It was a silly mistake by me, a typo within createPoint was setting temp[65] to true.... Im not exactly sure how an out-of-bounds array would change "l" but once I fixed that it doesn't seem to get changed anymore and it would make sense that it was changing to 1 and 0 since temp is a bool, im not sure how I didnt expect something like that.

Sorry to bother you when it turns out I just hadn't inspected one of my functions hard enough.
Last edited on
Topic archived. No new replies allowed.