| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 476 人关注过本帖
标题:帮忙看下错误的地方
只看楼主 加入收藏
田呓语
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-4-13
收藏
 问题点数:0 回复次数:4 
帮忙看下错误的地方
#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;
        }
    }
}
搜索更多相关主题的帖子: include create 
2015-04-14 22:17
鲤鱼爱美丽
Rank: 8Rank: 8
来 自:冥界
等 级:蝙蝠侠
威 望:5
帖 子:288
专家分:843
注 册:2015-4-8
收藏
得分:0 
。。。。。。。。。。。。。

代码代码,带着的石头码!!!
2015-04-14 23:53
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
回复楼主:我不知道哪里有错误  因为肉眼看不出来

DO IT YOURSELF !
2015-04-15 08:35
lowrie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:81
专家分:138
注 册:2015-3-12
收藏
得分:0 
这么长的代码.....没法看呀
2015-04-15 11:53
无功
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:44
专家分:168
注 册:2015-4-12
收藏
得分:0 
可以先按照编译器把语法错误改正呀
2015-04-15 16:18
快速回复:帮忙看下错误的地方
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035325 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved