为了账号安全,请及时绑定邮箱和手机立即绑定

将一个文件分成几个源文件,链表为例

将一个文件分成几个源文件,链表为例

C
DYXnice216444 2016-06-21 20:10:44
d1.c:#include<stdio.h>#include"f1.h"main(){    struct stu *head;    int num;    head=creat();    list(head);    scanf("%d",&num);    head=del(head,num);    list(head);}d2.c:#include<stdio.h>#include<stdlib.h>#include"f1.h"#define LEN sizeof(struct stu )struct stu *creat(void){    struct stu *p1,*p2;    struct stu *head=NULL;    p1=p2=(struct stu *)malloc(LEN);    scanf("%d%f%s",&p1->num,&p1->score,&p1->gender);    whil(p1->num!=0)    {        if(head==NULL)            head=p1;        else            p2->next=p1;        p2=p1;        p1=(struct stu *)malloc(LEN);        scanf("%d%f%s",&p1->num,&p1->score,&p1->gender);    }    p2->next=NULL;    free(p1);    return head;};struct stu *del(struct stu *head,int num){    struct stu *p1,*p2;    p1=p2=(struct stu *)malloc(LEN);    if(head==NULL)        printf("Á´±íΪ¿Õ");    else    {        p1=head;        while(num!=p1->num&&p1->next!=NULL)        {            p2=p1;            p1=p1->next;        }        if(num==p1->num)        {            if(head=p1)                head=p1->next;            else                p2->next=p1->next;        }    }    free(p1);    return head;};void list(struct stu *head){    struct stu *p;    p=head;    while(p!=NULL)    {        printf("%d%f%s",p->num,p->score,p->gender);        p=p->next;    }}f1.h:#ifndef f1_h#define f1_hstruct stu {    int num;    float score;    char gender[50];    struct stu *next;};struct stu *creat(void);struct stu *del(struct stu *head,int num);void list(struct stu *head);#endif // f1_h
查看完整描述

1 回答

?
请在夏天叫醒我

TA贡献10条经验 获得超0个赞

什么意思- -。

查看完整回答
反对 回复 2016-07-07
  • 1 回答
  • 0 关注
  • 1280 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信