How to stop a floodfill printing problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CHRIS FOLEY
    New Member
    • Nov 2011
    • 4

    How to stop a floodfill printing problem.

    How do I make the end part stop printing and only print the filled shape?

    In this program the user enters a shape with **** and then the program prints out a filled shape, filling it with *** and beginning the shape's filling at the point where the user indicated.

    Thanks
    Chris


    #include "simpio.h"
    #include <stdio.h>
    #include "genlib.h"

    #define size 50;

    void GetArray(char arr[][50]);
    void fill(char arr[][50], int row, int col);
    void disp(char arr[][50]);

    main()
    {
    char arr[50][50];
    int row, col;

    GetArray(arr);
    printf("\nEnter row of interior point: ");
    row = GetInteger();
    printf("Enter column of interior point: ");
    col = GetInteger();
    fill(arr, row, col);
    disp(arr);
    getchar();
    system("pause") ;
    }

    void GetArray(char arr[][50])
    {
    char input;
    int i,j;
    for(i=0;i<50;i+ +)
    {
    for(j=0;j<50;j+ +)
    {
    arr[i][j] = ' ';
    }
    }
    printf("Enter the closed shape using asterisks and spaces. \nKeep the number of rows and columns under 50\n");
    printf("To signal the end of the input, type '!'. \nUse the 'enter' key to move down rows\n\n");
    i = 0;
    j = 0;
    while(TRUE)
    {
    input = getchar();
    if(input == 'r')
    i++;
    else if(input == '!')
    break;
    else
    {
    arr[i][j] = input;
    j++;
    }
    }
    i=0;
    j=0;
    printf("\n\nThe input shape is:\n");
    for(i=0;i<50;i+ +)
    {
    for(j=0;j<50;j+ +)
    {
    printf("%c",arr[i][j]);
    }
    }
    }

    void fill(char arr[][50], int row, int col)
    {
    if(arr[row][col]!=' '|| row>=50 || col>=50 || row<0 || col<0)
    {}
    else
    {
    arr[row][col] ='*';
    fill(arr,row+1, col);
    fill(arr,row-1,col);
    fill(arr,row,co l+1);
    fill(arr,row,co l-1);
    }
    }

    void disp(char arr[][50])
    {
    int i,j;

    printf("\nThe filled shape is:\n");
    for(i=0;i<50;i+ +)
    {
    for(j=0;j<50;j+ +)
    {
    printf("%c",arr[i][j]);
    }
    printf("\n");
    }
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You are making your fill function too complicated.

    First, there are no real mlti-dimensional arrays in C. Read this: http://bytes.com/topic/c/insights/77...rrays-revealed

    Second, if your starting point is a [row][col]. Then do a calculation where you multiply the row by 50 and add the col.

    Then fill from there as a one dimnsional array of row*col elements.

    Comment

    • CHRIS FOLEY
      New Member
      • Nov 2011
      • 4

      #3
      I am still trying but I think this is not much better. Any suggestions?

      #include "simpio.h"
      #include <stdio.h>
      #include "genlib.h"
      /*if(!arrays[x+1][y])fill(arrays,x+ 1,y);*/
      #define size 50;

      void GetArray(char arrays[][50]);
      void fill(char arrays[][50], int row, int col);
      void disp(char arrays[][50]);

      main()
      {
      char arrays[50][50];
      int row, col;

      GetArray(arrays );
      printf("\nEnter row of interior point: ");
      row = GetInteger();
      printf("Enter column of interior point: ");
      col = GetInteger();
      fill(arrays, row, col);
      disp(arrays);
      getchar();
      system("pause") ;
      }

      void GetArray(char arrays[][50])
      {
      char input;
      int number,number2;
      //initialize array
      for(number=0;nu mber<50;number+ +)
      {
      for(number2=0;n umber2<50;numbe r2++)
      {
      arrays[number][number2] = ' ';
      }
      }
      printf("Enter the closed shape using asterisks and spaces. \nKeep the number of rows and columns under 50\n");
      printf("To signal the end of the input, type '!' right after the shape. \nUse the 'enter' key to move down rows\n\n");
      number = 0;
      number2 = 0;
      //this loop is loading the shape into the array
      while(TRUE)
      {
      input = getchar();
      if(input == '\n')
      (number++ && number2++);
      else if(input == '!')
      break;
      else
      {
      arrays[number][number2] = input;
      number2++;
      }
      }
      number=0;
      number2=0;
      printf("\n\nThe input shape is:\n");
      for(number=0;nu mber<50;number+ +)
      {
      for(number2=0;n umber2<50;numbe r2++)
      {
      printf("%c",arr ays[number][number2]);
      }
      }
      }

      void fill(char arrays[][50], int row, int col)
      {
      /* there should be another way to do this,*/
      if(row>=50 || col>=50 || row<0 || col<0||arrays[row+1][col]!=' ' )
      {}
      else
      {
      /*printf("here") ; //I put this statement here as a test, the program is never coming here,
      so it is likely that the if statement is not doing what I expect.*/
      arrays[row][col] ='*';
      fill(arrays,row +1,col);
      fill(arrays,row-1,col);
      fill(arrays,row ,col+1);
      fill(arrays,row ,col-1);
      }
      }
      /*This is printing out the whole array, even if there are blank lines, */
      void disp(char arrays[][50])
      {
      int number,number2;

      printf("\nThe filled shape is:\n");
      for(number=0;nu mber<50;number+ +)
      {
      for(number2=0;n umber2<50;numbe r2++)
      {
      printf("%c",arr ays[number][number2]);

      }

      }
      }

      Comment

      • harender Chopra
        New Member
        • Nov 2011
        • 1

        #4
        can any body help me out how can i use radio button. where when i select the first radio button there is another disable and same with the other in asp.net

        Comment

        Working...