What is wrong with my code? It repeats the "Enter the next row:" statement more than once for each time its executed. And the characters turn in to brackets.
/*
* File: fill.cpp
* -----------------
* This program gets the perimeter of a closed shape
* as an input and fills in the area of the shape.
*/
#include <stdio.h>
#include "simpio.h"
#define size 3
void fill(int row, int column,char shape[size][size]);
int main()
{
char c;
char shape[size][size];
int m,n;
printf("This program gets the perimeter of a closed shape\n");
printf("as an input and fills in the area of the shape.\n");
printf("Enter the perimeter of the shape row by row.\n");
printf("Use '*' for the perimeter and ' ' for the inside of the shape.\n");
printf("Enter the first row: ");
for(m=0; m<=size-1; m++)
{
n=0;
while(n<=size-1)
{
c=getchar();
shape[m][n]=c;
printf("Enter the next row: ");
n++;
}
}
}
/****************************************fill**************************************/
/* This program fills in the area of the shape using a recursive function. */
void fill(int row,int column,char shape[size][size])
{
int m,n;
m=row;
n=column;
if(shape[m][n]!='*')
{
shape[m][n]='*';
fill(m,n+1,shape);
fill(m,n-1,shape);
fill(m-1,n,shape);
fill(m+1,n,shape);
}
}