帮忙看下错误的地方
#include<stdio.h>#include<stdlib.h>
typedef struct snake
{
int x;
int y;
struct snake *next;
}Snake;
Snake *create()
{
int x,y;
Snake *q,*p;
Snake *head=(Snake *)malloc(sizeof(Snake));
q=head;
printf("shu ru zuo biao,x,y:\n");
scanf("%d,%d",&x,&y);
while (x!=0) {
p=(Snake *)malloc(sizeof(Snake));
p->x=x;
p->y=y;
q->next=p;
q=p;
q->next=NULL;
printf("shu ru zuo biao,x,y:\n");
scanf("%d,%d",&x,&y);
}
return head;
}
void show()
{
Snake *head;
Snake *p=head->next;
while (p) {
printf("%d %d",p->x,p->y);
p=p->next;
}
printf("\n");
}
void Remove()
{
char c;
Snake *s,*p,*q;
p=s;
q=s;
int len=0,k=0,i=0;
while (q) {
q=q->next;
len++;
}
k=len;
printf("%d\n",len);
for (; len>0; len--) {
for (len=k-i-2; len>0; len--) {
p=p->next;
}
i++;
p->next->x=p->x;
p->next->y=p->y;
p=s;
}
switch (c) {
case 'd':
p->next->x=p->next->next->x;
p->next->y=p->next->next->y+1;
q=s;
p=s;
break;
case 'a':
p->next->x=p->next->next->x;
p->next->y=p->next->next->y-1;
q=s;
p=s;
case 'w':
p->next->x=p->next->next->x-1;
p->next->y=p->next->next->y;
q=s;
p=s;
case 's':
p->next->x=p->next->next->x+1;
p->next->y=p->next->next->y;
q=s;
p=s;
default:
break;
}
}
void Remove1()
{
int len=0,k=0,i=0;
char c;
Snake *s;
Snake *cop=s;
Snake *p=NULL,*q=NULL;
Snake *tmp=(Snake *)malloc(sizeof(Snake));
tmp->next=NULL;
while (cop->next) {
cop=cop->next;
}
cop->next=tmp;
p=s;
q=s;
while (q) {
q=q->next;
len++;}
k=len;
printf("%d\n",len);
for (;len>0;len-- )
{
for(int len=k-i-2;len>0;len--)
{
p=p->next;
}
i++;
p->next->x=p->x;
p->next->y=p->y;
p=s;
}
switch (c) {
case 'd':
p->next->x=p->next->next->x;
p->next->y=p->next->next->y+1;
q=s;
p=s;
break;
case 'a':
p->next->x=p->next->next->x;
p->next->y=p->next->next->y-1;
q=s;
p=s;
break;
case 'w':
p->next->x=p->next->next->x-1;
p->next->y=p->next->next->y;
q=s;
p=s;
break;
case 's':
p->next->x=p->next->next->x;
p->next->y=p->next->next->y;
q=s;
p=s;
break;
default:
break;
}
}
int Time()
{
int t1;
char c;
long long t2=t1*100000000;
for (t2; t2>0; t2--) {
if (scanf("%c",&c)) {
return 0;
}
}
}
int main()
{
Snake head=*create();
// show();
int k1=0,k2=0;
Snake *s=NULL,*p=NULL,*p2=NULL,*p3=NULL,*p4=NULL;
Snake *food=(Snake *)malloc(sizeof(Snake));
food->next=NULL;
food->x=rand()%10+0;
food->y=rand()%15+0;
while (food->x==0||food->x==9||food->y==0||food->y==14) {
food->x=rand()%10+0;
food->y=rand()%15+0;
}
p3=food;
s=create();
p=s;
int i,j;
while (1) {
for ( i=0; i<10; i++) {
for ( j=0; j<15; j++) {
while (p) {
if ((p->x==i)&&(p->y==j)) {
printf("#");
k1++;
if (p->x==p3->x&&p->y==p3->y) {
p4=(Snake *)malloc(sizeof(Snake));
p4->x=rand()%10;
p4->y=rand()%15;
while (p4->x==0||p4->x==9||p4->y==0||p4->y==14) {
p4->x=rand()%10+0;
p4->y=rand()%15+0;
}
p3=p4;
}
}
p=p->next;
}
p=s;
if (p3->x==i&&p3->y==j) {
printf("@");
k2++;
}if (i==0||i==9) {
printf("*");
}else if((j==0&&i!=0)||(j==0&&i!=9)||(j==14&&i!=0)||(j==14&&i!=9)){
printf("*");
}else if(k1==0&&k2==0){
printf(" ");
}
k1=0;
k2=0;
}
printf("\n");
}
char c,d;
int k3=0,k4=0,n=0,tmp1=0,tmp2=0;
c=getchar();
c=getchar();
switch (c) {
case 'a':
if ((p->next->x==p3->x)&&((p->next->y-1)==p3->y)) {
Remove1(c,p);
}else
{
Remove(c,p);
}
break;
case 'd':
if ((p->next->x==p3->x)&&((p->next->y+1)==p3->y)) {
Remove1(c,p);
}else
{
Remove(c,p);
}
break;
case 'w':
if (((p->next->x-1)==p3->x)&&(p->next->y==p3->y)) {
Remove1(c,p);
}else
{
Remove(c,p);
}
break;
case 's':
if (((p->next->x+1)==p3->x)&&(p->next->y==p3->y)) {
Remove1(c,p);
}else
{
Remove(c,p);
}
break;
default:
break;
}
system("clear");
if (p->next->x==0||p->next->x==10||p->next->y==0||p->next->y==15) {
printf("ni shu le\n");
exit(1);
}
tmp1=p->next->x;
tmp2=p->next->y;
p2=p->next->next;
while (p2) {
if (p2->x==tmp1&&p2->y==tmp2) {
printf("shu le\n");
exit(1);
}
p2=p2->next;
}
}
}