C语言中的递归形状填充程序
我必须制作一个程序,该程序采用用户用星号()绘制的形状周长,然后用星号()填充形状。C语言中的递归形状填充程序,c,arrays,char,fill,C,Arrays,Char,Fill,我必须制作一个程序,该程序采用用户用星号()绘制的形状周长,然后用星号()填充形状。 它编译得很好,但我的问题是,当我重新打印形状的周长时,它会打印一些时髦的符号,如: 1ÿu♤☺ x{⇦@ ☺ 另一个问题是,一旦执行填充,星号只会全部打印在一行上 这是我的代码(很长,对不起) #包括 #包括“simpio.h” #包括“genlib.h” void getArray(char数组[][20]); int getRow(无效); int getColumn(void); 空白填充(字符数组[
它编译得很好,但我的问题是,当我重新打印形状的周长时,它会打印一些时髦的符号,如: 1ÿu♤☺ x{⇦@ ☺ 另一个问题是,一旦执行填充,星号只会全部打印在一行上 这是我的代码(很长,对不起)
#包括
#包括“simpio.h”
#包括“genlib.h”
void getArray(char数组[][20]);
int getRow(无效);
int getColumn(void);
空白填充(字符数组[][20],整数行,整数列);
void dispArray(字符数组[][20]);
void dispMsg(void);
main()
{
字符数组[20][20];
int行,列;
dispMsg();
getArray(数组);
printf(“请输入程序开始填充的内部点。\n”);
row=getRow();
column=getColumn();
填充(数组、行、列);
dispArray(数组);
getchar();
}
void dispMsg(void)
{
printf(“此程序将要求您输入形状的轮廓,它将填充形状。\n”);
printf(“要输入形状的周长,请使用星号(*)和开始新行的键。\n”);
}
空白填充(字符数组[][20],整数行,整数列)
{
if(数组[行][列]!=''||行>20 | |行20 | |列
另一个问题是,一旦执行填充,星号只会全部打印在一行上
您从不打印NL
字符:
void dispArray(char array[][20])
{
int i, j;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
printf("%c", array[i][j]);
}
printf("\n");
}
}
您应该更改条件。您可能应该使用更简单的迭代方式。array[row][column]='*';
在这里使用比较运算符正常吗?为什么您会以如此疯狂的方式缩进代码?奇怪吗?哦,我不知道……还是初学者:)正确的方法是什么噢,谢谢。但是fill函数有什么问题吗?它什么都没做\@michaelferahiresilvafill()
不能填充你的数组?哦……谢谢你!但是为什么奇怪的1ÿu♤☺ x{⇦@ ☺ 重新打印输入时打印的字符array@MichaelFerashireSilva在调用fill()
后重新打印输入数组->时?在您的测试中,行
和列
的值是多少?我的意思是在getArray函数中,当我打印输入的数组时
void dispArray(char array[][20])
{
int i, j;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
{
printf("%c", array[i][j]);
}
printf("\n");
}
}
// what if row and column are equals to 5 by example?
void fill(char array[][20], int row, int column)
{
// If row = 5, then this condition is true, same for column = 5.
// The array will never be filled so !
if(array[row][column]!=' '||row>20||row<20||column>20||column<20)
{
}
else
{
array[row][column] = '*'; // By the way, you should use the assigment operator instead of comparison one.
fill(array, row, column+1);
fill(array, row+1, column);
fill(array, row, column-1);
fill(array, row-1, column);
}
}