Thread: 2 Dimensional Array Nightmare.

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

    Angry 2 Dimensional Array Nightmare.

    This is going to be a time consuming long post. I apologise. But this has been a problem that has plagued me for days.

    This is my grid:

    Code:
    ...........#.#.
    .#.#.#.#.#.....
    ...........#.#.
    .#.#.#.###.#.#.
    .....#.........
    .#.#.#.#.###.##
    I am supposed to count and number both the columns and the rows.

    * Rule for Column:
    There has to be 3 consecutive dots on the grid in a column.
    So this is the output i should get.

    Code:
    1.2.3.4.5.6#7#8
    .#.#.#.#.#.....
    ...........#.#.
    9#10#11#12###.#13#.
    .....#.........
    .#.#.#.#.###.##
    * Rule for Rows:
    There has to be 3 or more consecutive dots from left to right for there to be a row (bound by hashes or end of line. Here's the output that i get.

    Code:
    1..........#.#.
    .#.#.#.#.#2....
    3..........#.#.
    .#.#.#.###.#.#.
    4....#5........
    .#.#.#.#.###.##

    Everything's cool so far. But the problem is that i need an output that is a combination of BOTH the GRIDS shown above. The Row Grid and the Column Grid. This is the output i need to get:


    Code:
    1.2.3.4.5.6#7#8
    .#.#.#.#.#9....
    10..........#.#.
    11#12#13#14###.#15#.
    16....#17........
    .#.#.#.#.###.##


    I don't know how to GET THIS output and get the numbers right.

    Should i be using another array to do this? Any Help Appreciated.

    Thanks guys.



    Here's part of my code used to number the grids:

    Code:
    // For numbering COLUMNS
    
      countcolumn = 1;
      for(row=0; row<tall; row++){
        for(col=0; col<wide; col++){
          if ((row%3==0) && (grid[row][col]=='.') && (grid[row+1][col]=='.') && (grid[row+2][col]=='.')){
    	printf("%d", countcolumn++);
          }
          else{
    	printf("%c", grid[row][col]);
          }
        }
        printf("\n");
      }
    
      printf("\n");
      printf("\n");
    
    // for Numbering ROWS.
    
      countrow = 1;
      row      = 0;
      col      = 0;
      onoroff     = 0;
    
      for(row=0; row<tall; row++){
        for(col=0; col<wide; col++){
      
          if ((grid[row][col]=='.') && (grid[row][col+1]=='.') && (grid[row][col+2]=='.')){
    	if (onoroff==0){
    	  printf("%d", countrow++);
    	  onoroff = 1;
    	  continue;
    	}
    	printf("%c", grid[row][col]);
          }
          else{
    	printf("%c", grid[row][col]);
    	flag = 0;
          }
        
        }
        printf("\n");
      }

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Nearly There

    Hey thanks for that. That was really neat code. Except for one

    The code below makes it so that the only thing that Column counting is only done in r%3 and row counting is done in all the other rows.

    Whereas what i need to do is to have row counting done in all rows including r%3 and column counting only in r%3.

    Code:
    for ( r = 0 ; r < ROWS ; r++ ) {
            if ( r % 3 == 0 ) label_columns(r);
            else label_rows(r);
            printf( "\n" );

    I tried to change the code to

    Code:
    if (r%3== 0){
    label_columns(r);
    label_rows(r);
    printf("\n");
    But this messes up entirely. adds new characters the numbers get messed up etc.


    To Test this. I have made up a new grid.



    Code:
    NEW GRID
    
    ...............
    ............##.
    #.#.#.##.#.##.#
    ...............
    ###############
    ..#..#..#..#..#
    The Output that i get from my code for this grid:

    Code:
    COLUMNS:
    
    .1.2.3..4.5....
    ............##.
    #.#.#.##.#.##.#
    ...............
    ###############
    ..#..#..#..#..#
    
    ROWS:
    
    1..............
    2...........##.
    #.#.#.##.#.##.#
    3..............
    ###############
    ..#..#..#..#..#

    The Output that i get from your code:

    Code:
    .1.2.3..4.5....
    6...........##.
    #.#.#.##.#.##.#
    ...............
    ###############
    ..#..#..#..#..#

    The output that i desired (COMBINED Row and Column Numbering):

    Code:
    12.3.4..5.6....
    7...........##.
    #.#.#.##.#.##.#
    8..............
    ###############
    ..#..#..#..#..#

    I am not really sure how to accomplish this. hmmmm..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  2. How To pass 2 dimensional array of strings to a function
    By chottachatri in forum C Programming
    Replies: 15
    Last Post: 01-25-2008, 02:20 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Replies: 5
    Last Post: 11-20-2001, 12:48 PM