#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
void myprintf(int a, int b, int** real_mine,int ROW,int COL)//Print the changed mine block
{
int i, j = 0;
for (i = 0;i < ROW;i++)
{
for (j = 0;j < COL;j++)
{
if (j==b-1&&i==a-1)
{
printf("**");
}
else
{
printf("%c%c", 161, 246);
}
}
printf("\n\n");
}
}
int main()
{
int i, j = 0;//Build the mine block
int ROW, COL;
printf("Input mine field width :\n");
scanf("%d", &ROW);
printf("Input min field height :\n");
scanf("%d", &COL);
printf("\n");
printf("Building the mine field. . . .\n");
printf("This is the mine field. . . .\n");
system("pause");
for (i = 0;i < ROW;i++)
{
for (j = 0;j < COL;j++)
{
printf("%c%c", 161, 246);
}
printf("\n\n");
}
int** real_mine;//Use dynamic array to store width and hight
real_mine = (int**)malloc(ROW * sizeof(int));
for (i = 0;i < ROW;i++)
{
real_mine[i] = (int*)malloc(COL * sizeof(int*));
}
for (i = 0;i < ROW;i++)//Initialize the mine block
{
for (j = 0;j < COL;j++)
{
real_mine[i][j] = '0';
}
}
//Set mines
int x;
int y;
int count;
printf("please input the numbers of mines :");
scanf("%d", &count);
int n = 0;
while (n < count)
{
printf("please input the detailed position :");
scanf("%d", &x);
scanf("%d", &y);
if (real_mine[x-1][y-1] == '0' && y>0 && x > 0 && x < COL && y < ROW)
{
real_mine[x-1][y-1] = '1';
n++;
}
else
{
printf("input error\n");
printf("please input again \n");
}
}
//Sweep mines
printf("please input position to sweep mines");
int a = 0;
int b = 0;
int COUNT = 0;
for (COUNT = 0;COUNT < count;)
{
scanf("%d", &a);
scanf("%d", &b);
while (a > 0 && b > 0 && b < COL&& a < ROW)
{
if (real_mine[a-1][b-1] == '1')
{
myprintf(a, b, real_mine,ROW,COL);
COUNT++;
break;
}
else if (real_mine[a-1][b-1] == '0')
{
printf("sorry no mines,try again\n");
break;
}
else
{
printf("input error\n");
printf("please input again \n");
break;
}
}
}
//Success
printf("you have found all the mines \ncongratulations !");
system("pause");
return 0;
}
现在问题是我不知道怎么在打印函数中遍历每一次的结果,就是打印时要遍历之前的✳️,全部打印在一个表格中,怎么实现啊
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。