| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 940 人关注过本帖
标题:大家帮我看看这个程序!
只看楼主 加入收藏
whbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:180
专家分:139
注 册:2010-3-31
结帖率:89.66%
收藏
已结贴  问题点数:20 回复次数:7 
大家帮我看看这个程序!
大家帮我看看这个程序!输入时候一直输下去了,没有反应(创建链表的时候)!
程序代码:
#include <stdio.h>
#include <stdlib.h>


 struct student

 { 
     char name[8];
     float high;
     long int weight;
     struct student *next;

 };


 int n,i;

 struct student *creat()//创建链表
 { 
      i=1;
     struct student *p,*head,*stud;
     head=NULL;
     stud=p=(struct student *)malloc(sizeof(struct student));
     printf("请输入学生 %d 的身高体重姓名:",i);
     scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);
    
     while(stud->high!=0)
     {
         n++;
         if(n==1)
         {  
             head=stud;
             head->next=NULL;
         }
         else
             p->next=stud;
             p=stud;
          stud=(struct student *)malloc(sizeof(struct student));
          printf("请输入学生 %d 的姓名身高体重:",++i);
          scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);
         
     }
     p->next=NULL;
     return(head);

 }



 struct student * search(struct student *head)//找出高度最高的那个学生
 {  
     struct student *p,*q,*t;
     float k;
     t=p=head;
     do
     { 
         if(t->high<p->high)
         {
              k=t->high;
              t->high=p->high;
              p->high=k;
              q=p;
         }
         p=p->next;
     }while(p!=NULL);
         return q;


 }


 struct student * find(struct student *head)//找出体重最重的那个学生
 { 
     struct student *p,*q,*t;
     int m;
     t=p=head;
     do
     {
         if(t->weight<p->weight)
         {
             m=t->weight;
             t->weight=p->weight;
             p->weight=m;
             q=p;
         }
         p=p->next;
     }while(p!=NULL);
    
    return q;

 }



 void  main(void)

 { 
     struct student *p,*q,*head;
     head=creat();
     p=search(head);
     printf("%s%f%ld",p->high,p->weight,p->name);
     q=find(head);
     printf("%s%f%ld",p->high,p->weight,p->name);
     
     

 }

搜索更多相关主题的帖子: next color 
2010-12-14 09:51
fsfg_yan
Rank: 1
等 级:新手上路
帖 子:1
专家分:2
注 册:2008-10-4
收藏
得分:2 
scanf("%s%f%ld",&stud->high,&stud->weight,&stud->name);这一句有问题!
2010-12-14 11:26
freedgun
Rank: 5Rank: 5
等 级:职业侠客
帖 子:147
专家分:302
注 册:2010-11-11
收藏
得分:2 
(16) : error C2143: syntax error : missing ';' before 'type'
(17) : error C2065: 'head' : undeclared identifier
(17) : warning C4047: '=' : 'int ' differs in levels of indirection from 'void *'
(18) : error C2065: 'stud' : undeclared identifier
(18) : error C2065: 'p' : undeclared identifier
(18) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct student *'
(20) : error C2223: left of '->high' must point to struct/union
(20) : error C2223: left of '->weight' must point to struct/union
(20) : error C2223: left of '->name' must point to struct/union
(22) : error C2223: left of '->high' must point to struct/union
(28) : error C2223: left of '->next' must point to struct/union
(31) : error C2223: left of '->next' must point to struct/union
(33) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct student *'
(35) : error C2223: left of '->high' must point to struct/union
(35) : error C2223: left of '->weight' must point to struct/union
(35) : error C2223: left of '->name' must point to struct/union
(38) : error C2223: left of '->next' must point to struct/union
(39) : warning C4047: 'return' : 'struct student *' differs in levels of indirection from 'int '
执行 cl.exe 时出错.

001.obj - 1 error(s), 0 warning(s)
看不明白哪有问题

有什么样的付出,就有什么样的收获!!
2010-12-14 11:59
gaochizhen33
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:114
专家分:101
注 册:2010-11-4
收藏
得分:2 
创建的时候内层循环没有结束语句啊
2010-12-14 12:17
venus85
Rank: 6Rank: 6
等 级:侠之大者
帖 子:159
专家分:477
注 册:2010-11-27
收藏
得分:2 
我帮你改了一部分,剩下的是类似的,你自己再看看,有问题再讨论
程序代码:
#include <stdio.h>
#include <stdlib.h>
struct student
{    char name[8];
     float high;
     long int weight;
     struct student *next;
};
     int n,i;
struct student *creat()//创建链表
{
      i=1;
     struct student *p,*head,*stud;
     head=NULL;
     stud=head=(struct student *)malloc(sizeof(struct student));
     printf("请输入学生 %d 的身高体重姓名:",i);
     scanf("%f%ld%s",&stud->high,&stud->weight,stud->name);
   while(stud->name!="over") //以姓名为over作为输入链表结束标志
     { p= (struct student *)malloc(sizeof(struct student));
       stud->next=p;
       stud=p;
       scanf("%d%ld%s",&p->high,&p->weight,p->name);
     }
      p->next=NULL;
      return(head);
}
struct student * search(struct student *head)//找出高度最高的那个学生
{ 
     struct student *p,*q,*t;
     p=head;
     while(p!=NULL&&p->next!=NULL)
     {
         if(p->high>=p->next->high)
           t=p;
           p=p->next;
     }
         return t;
}

void  main(void)
{
     struct student *p,*h;
     h=creat();
     p=search(h);
     printf("%f%ld%s",p->high,p->weight,p->name);
     /*q=find(h);
     printf("%s%f%ld",p->high,p->weight,p->name);*/
}

2010-12-14 15:45
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:2 
楼上的   你往你的程序里面全输进去0  看看是什么样的   

                                         
===========深入<----------------->浅出============
2010-12-14 16:14
xiaomarn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:348
专家分:2026
注 册:2009-3-18
收藏
得分:2 
程序代码:
#include <stdio.h>
#include <stdlib.h>

struct student
{
    char name[8];
    float high;
    long int weight;
    struct student *next;
};

int n,i;

struct student *creat()//创建链表
{

    struct student *p,*head,*stud;
    int r;
    

    i=1;
    head=NULL;
    stud=p=(struct student *)malloc(sizeof(struct student));
    printf("请输入学生 %d 的身高体重姓名:",i);
    r=scanf("%f %ld %s",&stud->high,&stud->weight,&stud->name);
    if(r!=3)
    {
        printf("input error!\n");
        exit(1);
    }

    while(stud->high!=0)
    {
        n++;
        if(n==1)
        { 

            head=stud;
            head->next=NULL;
        }
        else
            p->next=stud;
        p=stud;
        stud=(struct student *)malloc(sizeof(struct student));
        printf("请输入学生 %d 的姓名身高体重:",++i);
        r=scanf("%f %ld %s",&stud->high,&stud->weight,&stud->name);
        if(r!=3)
        {
            printf("input error!\n");
            exit(1);
        }       

    }
    p->next=NULL;
    return(head);
}


struct student * search(struct student *head)//找出高度最高的那个学生
{ 

    struct student *p,*t;
    //float k;

    t=p=head;
    do
    {
        if(t->high < p->high)
        {
            t=p;
        }
        p=p->next;
    }while(p!=NULL);
        return t;
}

struct student * find(struct student *head)//找出体重最重的那个学生
{
    struct student *p,*t;
    //int m;

    t=p=head;
    do
    {
        if(t->weight<p->weight)
        {
            t=p;
        }
        p=p->next;
    }while(p!=NULL);
  

    return t;
}


void  main(void)
{
    struct student *p,*q,*head;

    head=creat();
    if(n==0)
    {
        exit(1);
    }
    p=search(head);
    printf("%f %ld %s\n",p->high,p->weight,p->name);
    q=find(head);
    printf("%f %ld %s\n",q->high,q->weight,q->name);   

}
这个程序好奇怪!

额。。。有问题!让我再改改!


[ 本帖最后由 xiaomarn 于 2010-12-14 17:14 编辑 ]
2010-12-14 17:04
whbc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:180
专家分:139
注 册:2010-3-31
收藏
得分:0 
回复 7楼 xiaomarn
嗯,请大侠指点了!!谢谢!!

付出终将有回报!Ibelieve!
2010-12-14 23:19
快速回复:大家帮我看看这个程序!
数据加载中...
 
   



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

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