how to print an array like in this picture..

This is a discussion on how to print an array like in this picture.. within the C Programming forums, part of the General Programming Boards category; i noticed the problem in this code insited the board it creates double "||" instead of one "|" how to ...

  1. #16
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i noticed the problem in this code
    insited the board it creates double "||" instead of one "|"
    how to fix it so every wal will be "|"
    Code:
    void printBoard(char board[N][N],int size){
    int index,kndex;
     for(index=0;index<size;index++)
    {
         for(kndex=0;kndex<size;kndex++)
        {
             printf("+-+");
    
         }
         printf("\n");
         for(kndex=0;kndex<size;kndex++)
        {
             printf("|%c|",board[index][kndex]);
         }
         printf("\n");
    
     }
      for(kndex=0;kndex<size;kndex++)
       {
             printf("+-+");
    
         }
    }

  2. #17
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > how to fix it so every wal will be "|"
    Jeez, how hard can it be to delete one of the | you're printing???
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #18
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    there is a double wall inside the board i need only one "|"

    http://img261.imageshack.us/img261/5066/42964910uf4.gif

    i tried to change the printf but it makes a total mess
    Last edited by transgalactic2; 01-03-2009 at 06:27 AM.

  4. #19
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    this what happens when i remove one "|"
    http://img237.imageshack.us/img237/8882/11479923wg0.gif

    ??
    Code:
    void printBoard(char board[N][N],int size)
    {
        int index,kndex;
        for(index=0;index<size;index++)
        {
           for(kndex=0;kndex<size;kndex++)
           {
               printf("+-+");
           }
           printf("\n");
           for(kndex=0;kndex<size;kndex++)
           {
               printf("|%c",board[index][kndex]);
           }
           printf("\n");
    
     }
    	
      for(kndex=0;kndex<size;kndex++)
      {
             printf("+-+");
    
      }
      
      printf("\n");
    }

  5. #20
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

  6. #21
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i solved it

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Print Array in reverse order
    By swgh in forum C++ Programming
    Replies: 6
    Last Post: 11-06-2007, 12:41 PM
  3. i want to print a array
    By timhxf in forum C Programming
    Replies: 2
    Last Post: 01-07-2007, 03:25 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

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