以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 C/C++编程思想 』  (http://bbs.xml.org.cn/list.asp?boardid=61)
----  怎么输出个数总是比结构体成员多?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=61&rootid=&id=44828)


--  作者:ylq0891
--  发布时间:4/4/2007 9:07:00 AM

--  怎么输出个数总是比结构体成员多?
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
char name[10];
int later;
int speak;
float score1;
float score2;
float score3;
int kcxghd;
float sx;
int sleep;
struct student *next;
};
int n;
struct student *creat(void)
{struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *) malloc(LEN);
scanf("%ld%s%d%d%f%f%f%d%f%d",&p1->num,&p1->name,&p1->later,&p1->speak,&p1->score1,&p1->score2,&p1->score3,&p1->kcxghd,&p1->sx,&p1->sleep);
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);
  scanf("%ld%s%d%d%f%f%f%d%f%d",&p1->num,&p1->name,&p1->later,&p1->speak,&p1->score1,&p1->score2,&p1->score3,&p1->kcxghd,&p1->sx,&p1->sleep);
  }
p2->next=NULL;
return(head);
}
void print(struct student *head)
{struct student *p;
printf("\nNow These %d records are :\n",n);
p=head;
if(head!=NULL)
  do
  {printf("%ld%s%d%d%f%f%f%d%f%d\n",p->num,p->name,p->later,p->speak,p->score1,p->score2,p->score3,p->kcxghd,p->sx,p->sleep);
  p=p->next;
  }while(p!=NULL);
}
void main()
{struct student * head;
printf("input records:\n");
head=creat();
print(head);
}
怎么输出个数总是比结构体成员多?请帮忙看看!
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
6,875.000ms