Just checks if sqr value is a multiple of COLS, and sqr is non zero -- if so, print out a newline char so we have another row to display on.Code:if(sqr % COLS==0 && sqr) printf("\n");
This is a discussion on Using functions with pointer arguments - Connect 4 within the C Programming forums, part of the General Programming Boards category; Code: if(sqr % COLS==0 && sqr) printf("\n"); Just checks if sqr value is a multiple of COLS, and sqr is ...
Just checks if sqr value is a multiple of COLS, and sqr is non zero -- if so, print out a newline char so we have another row to display on.Code:if(sqr % COLS==0 && sqr) printf("\n");
I'm running into trouble again
This time I'm attempting to store the lowest row value of the columns to an int array, so I can keep track of the next piece dropped into that column. Here is my test code for the first column (since I'm dealing with a single array of length 42, the first column starts at position 0 and ends at 35, with 7 unit increment each time):
I'm looping through the 6 rows of the first column starting at index 35 (the highest position), with a decrement of 7 each time. If a slot is found to be occupied, then the lowest empty row is right above it, so I would return that index + 7. That number will finally be assigned to the first index of the int array top, which is top[0]. I tried to compile it but it didn't work.Code:int top[7]; //declaring the array that will holds the position //of the lowest empty row of each column // printf("size is: %d \n", sizeof(top)); // printf("first element is: %d \n", top[0]); int top_0; for (top_0 = 35; top_0 >= 0; top_0-=7){ if (grid[top_0] != '-') { top_0+=7; top[0] = top_0; break; } }Thanks for your help in advance guys !
"didn't work" is not a useful problem description. (I recommend reading How To Ask Questions The Smart Way)
What exactly didn't work? Did you get errors/warnings from the compiler? Did your program crash? Did you get an unexpected result?
Bye, Andreas