| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1721 人关注过本帖
标题:【求助】研究此程序5个小时还是没进展,希望大家帮忙
只看楼主 加入收藏
hj821165254
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-6-30
收藏
 问题点数:0 回复次数:13 
【求助】研究此程序5个小时还是没进展,希望大家帮忙
学校要求用链表编一个学生成绩管理系统,我在第一步成绩输入和输出就出问题了,输入成绩时在输入number那输入0不结束while循环,连续输入0倒是可以结束while循环,但是在输出时就成了死循环。求教高手如何解决。程序可能运行下会更好解决吧。谢谢大家帮忙,第一次发帖,请多指教。
程序如下:
#include<stdio.h>
#include<malloc.h>
#include <string.h>
#define NULL 0
#define len sizeof(struct student)

struct student
{long num;
 char name[20];
 float msco;
 float csco;
 float esco;
 struct student *next;
};
 int n;
 struct student *creat(void)
{
 struct student *head;
 struct student *p1,*p2;
 n=0;
 p1=p2=(struct student *)malloc(len);
 printf("please input the number of the student:");
 scanf("%ld",&p1->num);
 printf("please input the name of the student:");
 scanf("%s",&p1->name);
 printf("please input the math of the student:");
 scanf("%f",&p1->msco);
 printf("please input the cprogram of the student:");
 scanf("%f",&p1->csco);
 printf("please input the english of the student:");
 scanf("%f",&p1->esco);
 head=NULL;
 while(p1->num!=0)
  {n=n+1;
   if(n==1)head=p1;
   else p2->next=p1;
   p2=p1;
   p1=(struct student *)malloc(len);
   printf("please input the number of the student:");
   scanf("%ld",&p1->num);
   printf("please input the name of the student:");
   scanf("%s",&p1->name);
   printf("please input the math of the student:");
   scanf("%f",&p1->csco);
   printf("please input the cprogram of the student:");
   scanf("%f",&p1->esco);
   printf("please input the english of the student:");
   scanf("%f",&p1->name);
  }
 p2->next=NULL;
 return(head);
}
void print(struct student *head)
{
 struct student *p;
 p=head;
 if(head!=NULL)
  do
   {printf("%d",p->num);
    printf("%s",p->name);
    printf("%f",p->msco);
    printf("%f",p->csco);
    printf("%f",p->esco);
   }while(p!=NULL);
}
main()
{
float arg,*point=&arg;
struct student *head;
head=creat();
print(head);
}
搜索更多相关主题的帖子: 进展 float student struct 
2008-06-30 23:07
cxhiou
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2007-6-13
收藏
得分:0 
void main()

2008-06-30 23:18
hj821165254
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-6-30
收藏
得分:0 
回复 2# cxhiou 的帖子
按你的修改后还是不对 不过还是谢谢你啊
2008-06-30 23:21
界水乘风
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2008-06-30 23:33
hj821165254
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-6-30
收藏
得分:0 
回复 4# 界水乘风 的帖子
能不能说清楚一点,我刚学没多久,看不懂你写的什么意思哦。非常感谢!
2008-06-30 23:36
界水乘风
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2008-06-30 23:39
hj821165254
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-6-30
收藏
得分:0 
回复 5# hj821165254 的帖子
知道原因也修改了,非常感谢啊!!
但还有个问题想请教下,就是前面的这一段输入的问题,为什么我在num处输入0他还是不结束while循环呢?

while(p1->num!=0)
  {n=n+1;
   if(n==1)head=p1;
   else p2->next=p1;
   p2=p1;
   p1=(struct student *)malloc(len);
   printf("please input the number of the student:");
   scanf("%ld",&p1->num);
   printf("please input the name of the student:");
   scanf("%s",&p1->name);
   printf("please input the math of the student:");
   scanf("%f",&p1->csco);
   printf("please input the cprogram of the student:");
   scanf("%f",&p1->esco);
   printf("please input the english of the student:");
   scanf("%f",&p1->name);
  }
p2->next=NULL;
return(head);
}
2008-06-30 23:49
hj821165254
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-6-30
收藏
得分:0 
现在的程序修改如下
前面的问题都已经解决,但是新问题又来了,输出的时候输出不完整(name项输不出来)且多输入几次还会产生乱码。
希望大家能帮帮我 不胜感谢!
#include<stdio.h>
#include<malloc.h>
#include <string.h>
#define NULL 0
#define len sizeof(struct student)
struct student
{long num;
 char name[20];
 float msco;
 float csco;
 float esco;
 struct student *next;
};
 int n;
 struct student *creat()
{
 struct student *head;
 struct student *p1,*p2;
 n=0;
 do
 {
   p1=(struct student *)malloc(len);
   printf("please input the number of the student:");
   scanf("%ld",&p1->num);
   if(p1->num==0)break;
   printf("please input the name of the student:");
   scanf("%s",&p1->name);
   printf("please input the math of the student:");
   scanf("%f",&p1->csco);
   printf("please input the cprogram of the student:");
   scanf("%f",&p1->esco);
   printf("please input the english of the student:");
   scanf("%f",&p1->name);
   n=n+1;
   if(n==1)head=p1;
   else p2->next=p1;
   p2=p1;
  }while(p1->num!=0);
 p2->next=NULL;
 return(head);
}
void print(struct student *head)
{
 struct student *p;
 p=head;
 if(head!=NULL)
  do
   {printf("%d",p->num);
    printf("%s",p->name);
    printf("%7.2f",p->msco);
    printf("%7.2f",p->csco);
    printf("%7.2f",p->esco);
    p=p->next;
   }while(p!=NULL);
}
main()
{
float arg,*point=&arg;
struct student *head;
head=creat();
print(head);
}
2008-07-01 02:28
卧龙孔明
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
收藏
得分:0 
[bo][un]cxhiou[/un] 在 2008-6-30 23:18 的发言:[/bo]

void main()

算了,不过什么了,误导人啊........

My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2008-07-01 07:26
mqh21364
Rank: 1
等 级:新手上路
帖 子:642
专家分:0
注 册:2008-2-28
收藏
得分:0 
p->name是字符串,输入的时候不用加&

前不见古人,后不见来者。念天地之悠悠,独怆然而涕下。
2008-07-01 09:31
快速回复:【求助】研究此程序5个小时还是没进展,希望大家帮忙
数据加载中...
 
   



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

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