该楼层疑似违规已被系统折叠隐藏此楼查看此楼
如题,程序如下:
#include
#include //malloc,calloc,free,realloc头文件
#define LEN sizeof(struct Student)
struct Student
{long num;
float score;
struct Student *next;
};
int n; //到这里都是一些初始定义
struct Student *creat(void) //这里开始定义了一个函数creat
{
struct Student *head,*p1,*p2;
n=0;
p1=p2=(struct Student*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
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,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return (head);
} //到这里creat函数定义部分结束一般函数定义都写后面这个写前面了,区别?
int main() //这里开始main函数
{
struct Student *pt;
pt=creat(); //不懂在这点,没声明,直接就调用了??编译运行没错误
printf("\nnum:%ld\nscore:%5.1f\n",pt->num,pt->score);
return 0;
}
函数调用,涉及到动态链表就不用声明了么??