how to put char in board

This is a discussion on how to put char in board within the C Programming forums, part of the General Programming Boards category; I am trying to take the values entered into the array and populate the display(board) function in those coordinates. I ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    42

    how to put char in board

    I am trying to take the values entered into the array and populate the display(board) function in those coordinates. I can't figure out how to populate the display with 'Q' in the correct coordinates.
    Code:
    #include <stdio.h>
    #include <ctype.h>
    #define SIZE 8 /* Size of board*/
    
    /* function prototype */
    void display(char board[] [SIZE]);
    int valid_moves(char board[] [SIZE], int moves[] [SIZE], char player);
    
    void main()
    {
          char board [SIZE] [SIZE] ={ 0 }; /* The board*/
          int moves[SIZE] [SIZE] ={0}; /* valid moves */
          int row = 0;
          int col = 0;
          char queenie = 'Q';     /* user selection*/
          char y =0;        /* column letter*/
          int x =0;         /* row number*/
          char player = 'Q';
    
           /* empty all the squares */
          for(row = 0; row < SIZE; row++)
            for(col = 0; col < SIZE; col++)
              board[row] [col] = ' ';
    
    
    
          display(board);         /* display the board */
          fflush(stdin);          /*flush the buffer: keyboard--stdin*/
          printf("please enter the row and column to place the queen:");
          scanf("%d%c", &x, &y);
          printf("%d %c\n",x ,y);
          board[x][y]='Q';
          display(board);
          if(x<0 && y<0 || x>SIZE && y>SIZE)
          {
                printf(" That is an invalid entry!\n");
          }
          /*else &x*/
    }
    
    /* display board funtion definition*/
    void display(char board[] [SIZE])
    {
          int row = 0;      /* row index */
          int col = 0;      /* col index */
          char col_label = 'a';         /* column label */
    
          printf("\n ");    /*start top line */
          for(col = 0; col<SIZE; col++)
          printf("   %c", col_label+col);    /* display the top line*/
          printf("\n");     /*end of top line*/
    
    /*display  the intermediate rows*/
          for(row = 0; row < SIZE; row++)
          {
          printf("   +");
          for(col = 0; col<SIZE; col++)
          printf("---+");
          printf("\n%2d|",row + 1);
    
          for(col = 0; col< SIZE; col++)
          printf(" %c |", board[row][col]);   /* display counters in row*/
          printf("\n");
          }
    
          printf("   +");   /*start the bottom line*/
          for(col = 0; col<SIZE ; col++)
          printf("---+");   /*display the bottom line*/
          printf("\n");     /* end bottom line*/
          }

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    will not look at code that has not been properly tagged!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    42

    never mind i figured it out

    never mind i figured it out. I always get the code tag wrong I put a \instead of a / in the [/code] tag

  4. #4
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    You can always go back and edit the post, it will properly tag the code.
    The keyboard is the standard device used to cause computer errors!

  5. #5
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    void main()
    Declaring main to return anything but int might not work, it really depends on if your compiler supports that. More specifically, if you compiler uses main's return like this
    Code:
    main(argc, argv);
    exit(0);
    It really doesn't matter what you return, the run-time startup code'll ignore it. That's why to be sure you actually return the right code you use exit instead of return. But, if main is called like this
    Code:
    exit(main(argc, argv);
    and you use void main you're likely to break something by causing the startup code to access an undefined value.
    fflush(stdin); /*flush the buffer: keyboard--stdin*/
    Well, fflush is only defined by C to work for output streams. Whether or not this line works depends on whether or not your compiler supports it. Also, stdin isn't necessarily the keyboard, it's just the standard input stream that could get input from anywhere. If you assume it's always the keyboard then you'll get burned eventually.

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    42
    Thanks. That is good information. I will heed it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 03:25 AM
  2. lvalue error trying to copy between structures
    By emanresu in forum C Programming
    Replies: 2
    Last Post: 11-16-2006, 06:53 AM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 11:28 PM
  4. Pick a number....
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 39
    Last Post: 01-19-2003, 07:27 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21