## 五子棋动态打印棋子，新手求给予帮助~~

Alfred_原子弹一号 发布于 2015/06/19 12:52

void draw(int len, struct location Array[N])
{
int i,j;
for (i = 0; i<len; i++)
{
if(i==0)
{
printf("%3d",i);
}
else
{
printf("%2d", i );
}
}
printf("\n");
for (i = 0; i<len; i++)
{
printf ("%2d", i);
for(j=0;j<len;j++)
{
if(Array[j].x==i&&Array[j].y==j)
{
printf(" O");
}
else
{
printf("十");
}

}
printf ("\n");
}

}

/// 上面是打印棋盘棋子的draw函数

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"draw.c"
#define N 20
void draw(int len, struct location points[]);
void main(int argc, char *argv[] )
{
struct location points[N]={0,0};
int len;
int j=1,i=0;
char *p=NULL,*q=NULL;
char *t;
int s[N]={0};
int a,b;
printf("\nTotal %d arguments\n",argc);
len=atoi(argv[1]);
p=strtok(argv[2], ";");
while(p!=NULL)
{
t = p;
p = strtok(NULL, ";");
q=strtok(t, ",");
while(q!=NULL)
{
s[j]=atoi(q);
if(j%2!=0)
{
points[i].x=s[j];
}
else
{
points[i].y= s[j];
i++;
}
j++;
q=strtok(NULL, ",");

}
}
draw(len, points);
for(i=3;i<len*len;i++)
{
printf("请输入落棋子的坐标如：3,4\n");
scanf("%d,%d", &points[i].x,&points[i].y);
if(points[i].x>len||points[i].y>len)
{
printf("输入棋子超出棋盘范围\n");
exit(0);
}
else
{
draw(len, points);
}
}

}