![]() | |
|
Welcome to the ABXZone Computer Forums forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Jul 2006
Posts: 5
| Nested looping in C - Im stuck So I thought I had a pretty good understanding of looping even though I missed class the day it was taught. However now I am in a conceptual mind**** of how to approach this. The assignment is to create a dynamic tic-tac-toe board using multidimensional arrays and functions (with array passing) here is what the output should look like: hxxp://i4.photobucket.com/albums/y108/phishkids11/toe1.jpg here is what I have so far, focusing on the display board part Code: // INCLUDES
#include <stdio.h>
// DEFINES
#ifndef __TRUE_FALSE__
#define __TRUE_FALSE__
#define TRUE 1
#define FALSE 0
#endif
// ROWS and COLS
#define ROWS 7
#define COLS 7
#define MARKONE 'X'
#define MARKTWO 'O'
#define BLANK ' '
// PROTOTYPES
void InitializeBoard(char[ROWS][COLS]);
void DisplayBoard(char[ROWS][COLS]);
int PlayerMove(int, int, char[ROWS][COLS], char);
// MAIN
int main() {
// declare variables
char board[ROWS][COLS];
// initialize board
InitializeBoard(board);
/*
// populate the board with moves
PlayerMove(1, 1, board, MARKONE);
PlayerMove(1, 2, board, MARKONE);
PlayerMove(4, 3, board, MARKONE);
PlayerMove(1, 1, board, MARKTWO);
PlayerMove(6, 2, board, MARKTWO);
PlayerMove(4, 12, board, MARKTWO);
*/
// display the board
DisplayBoard(board);
// exit program
return 0;
}
// FUNCTION IMPLEMENTATIONS
void InitializeBoard(char board[ROWS][COLS]) {
int i = 0, j = 0;
for(i = 0; i < ROWS; i++) {
for(j = 0; j < COLS; j++) {
board[i][j] = BLANK;
}
}
}
void DisplayBoard(char board[ROWS][COLS]) {
int i = 0, j = 0, k = 0;
printf("**************TIC-TAC-TOE**************\n\n");
for(i = 1; i <= COLS; i++) {
printf("%2d", i);
}
printf("\n\n");
}
/*
int PlayerMove(int row, int col, char board[ROWS][COLS], char symbol) {
}
*/ Any advice would be great, not necessarily with this particular problem but anything with looping that would help me understand it better would be great. |
| (Offline) | |
| | |||
| |
| | #2 |
| Back at the Zone! Join Date: Apr 2002 Location: NH, USA
Posts: 6,463
| Re: Nested looping in C - Im stuck For your DisplayBoard() function, just do it the same way you did the InitializeBoard() function. Just replace 'board[i][j] = BLANK' with the appropriate print function. Good luck!
__________________ Using my PC for work ATM, so no folding for now. |
| (Offline) | |
| | #3 |
| Registered User Join Date: Jul 2006
Posts: 5
| Re: Nested looping in C - Im stuck Alright, I am starting to get it. I just had to go back to the basics and play around a bit before tackling this. Thanks though =p |
| (Offline) | |
| | #4 |
| <unknown level> ![]() ![]() Join Date: Dec 2002 Location: AUSTRALIA
Posts: 3,880
| Re: Nested looping in C - Im stuck just on this "developers block" syndrome you seemed to be experiencing... I'm a big fan of design... ie: conceptualising the solution via a process of design which then gives you a skeletal structure in which to hang your code. I tend to use "structure" charts for this... and use cases of course... and activity diagrams or even sequence diagrams... I know this may be a trivial example for some ppl... coding top down has advantages (eg: speed) if you are very familiar and experienced with the solution domain... but otherwise... design!
__________________ *** Please note: any advertising within this post has been placed there by the site owner and NOT by me! ***"To Boldly Go..." |
| (Offline) | |
![]() |
| Thread Tools | |
| Display Modes | |
| |