设备管理系统 C语言程序

已知一公司需要登记购买的设备信息,设计一程序完成以下功能:
1)能从文件导入购买的设备信息,文件格式如下:
供应商 价格 购买日期 设备名称 设备编号购买部门
2)能从键盘录入购买的设备信息
3)能将购买的设备报废
4)查询指定设备编号购买信息
5)能根据设备编号删除购买记录
6)能将当前末报废的设备信息保存到文件


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct equipment 
{
    char name[50];
    char type[30];
    char num[30];
    float price;
    char term[30];
    char host[30];
    char date[9];
    struct equipment *next;
}EQU;
EQU *addEquipment(EQU *head,EQU *p)
{
    EQU *q;
    if(head==0)
    {
        head=p;
        q=p;
        printf("成功增加了一个设备信息!\n");
    }
    else
    {
        q=head;
        while(q->next!=0)
        {
            q=q->next;
        }
        q->next=p;
        q=p;
        printf("成功增加了一个设备信息!\n");
    }
    q->next=0;
    return head;
}
EQU *searchEquipment(EQU *head,char *p)
{
    EQU *ne,*be;
    if(head==0)
    {
        printf("当前没有设备可以查找!\n");
        return 0;
    }
    if(strcmp(head->name,p)==0)
    {
        printf("成功找到该设备!\n");
        return head;
    }
    be=ne=head;
    while(strcmp(ne->name,p)!=0&&ne->next!=0)
    {
        be=ne;
        ne=ne->next;
    }
    if(strcmp(ne->name,p)==0)
    {
        printf("成功找到该设备!\n");
        return ne;
    }
    else 
    {
        printf("没有找到!\n");
        return 0;
    }
}
EQU *delEquipment(EQU *head,char *p)
{
    EQU *be,*ne;
    if(head==0)
    {
        printf("没有设备可删除!\n");
        return head;
    }
    if(strcmp(head->date,p)==0)
    {
        be=head;
        head=head->next;
        free(be);
        printf("成功删除该设备!\n");
    }
    else
    {
        be=ne=head;
        while(strcmp(ne->date,p)!=0&&ne->next!=0)
        {
            be=ne;
            ne=ne->next;
        }
        if(strcmp(ne->date,p)==0)
        {
            be->next=ne->next;
            free(ne);
            printf("成功删除该设备!\n");
        }
        else printf("没有找到该设备!\n");
    }
    return head;
}
void releasechain(EQU *head)
{
    EQU *p;
    while(head!=0)
    {
        p=head;
        head=head->next;
        free(p);
    }
}
main()
{
    EQU *head=0,*t,*p;
    int i;
    char name[50],date[9];
    printf("菜单:\n");
    printf("1.设备增加\n");
    printf("2.设备查询\n");
    printf("3.设备删除\n");
    printf("请输入需要完成的功能序号,输入0时结束程序:");
    scanf("%d",&i);
    while(i!=0)
    {
        switch(i)
        {
            case 1:
                t=(EQU *)malloc(sizeof(EQU));
                printf("请输入需要增加的设备名称,类型,编号,价格,所属部门,领用人和购买日期:\n");
                scanf("%s %s %s %f %s %s %s",t->name,t->type,t->num,&t->price,t->term,t->host,t->date);
                head=addEquipment(head,t);
                break;
            case 2:
                printf("请输入需要查找的设备名:");
                scanf("%s",name);
                if((p=searchEquipment(head,name))!=0) 
                printf("该设备的类型为%s\n",p->type);
                break;
            case 3:
                printf("请输入需要删除的设备的购买日期:");
                scanf("%s",date);
                head=delEquipment(head,date);
                break;
        }
        printf("请输入需要完成的功能序号,输入0时结束程序:");
        scanf("%d",&i);
    }
    releasechain(head);
    return 0;
}