Thread: Using functions with pointer arguments - Connect 4

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    if(sqr % COLS==0 && sqr)
             printf("\n");
    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.

  2. #17
    Registered User
    Join Date
    Sep 2012
    Posts
    8
    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):

    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;
    		}
    	}
    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. Thanks for your help in advance guys !

  3. #18
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Thinh Cao View Post
    I tried to compile it but it didn't work.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-29-2012, 09:20 AM
  2. Replies: 5
    Last Post: 07-28-2011, 06:45 AM
  3. Functions as arguments
    By jw232 in forum C++ Programming
    Replies: 2
    Last Post: 04-19-2008, 11:11 AM
  4. Please help connect file pointer
    By ralphwiggam in forum C Programming
    Replies: 10
    Last Post: 10-02-2006, 09:55 AM
  5. functions and pointer arguments
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 01-08-2002, 05:04 PM