| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 319 人关注过本帖
标题:保存出问题了不知道为什么
只看楼主 加入收藏
ch307458491
Rank: 1
等 级:新手上路
帖 子:27
专家分:2
注 册:2012-10-4
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:1 
保存出问题了不知道为什么
#include "malloc.h"
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
typedef struct stu{

    long num;
    char name[20];
    char sex[5];
    float math;
    float english;
    float c;
    float computer;
    struct stu *next;
}stulink;
/******************************链表的创建*******************************/
stulink *creat()
{
    system("cls");
        void main_menu();
    stulink *head=NULL,*last=NULL;
    stulink *p;
   
    p=(stulink *)malloc(sizeof(stulink));
    printf("input the number:");
    scanf("%ld",&p->num);
    printf("input the name:");
    scanf("%s",p->name);
    printf("input the sex:");
    scanf("%s",p->sex);

    p->next=NULL;
    while (p->num!=0)
    {
        if (head==NULL)
        {
            head=p;
            last=p;
        }
        else
        {
            last->next=p;
            last=p;
        }
    p=(stulink *)malloc(sizeof(stulink));
    printf("input the number");
    scanf("%ld",&p->num);
     if (p->num)
     {
     printf("input the name:");
     scanf("%s",p->name);
     printf("input the sex ");
     scanf("%s",p->sex);
     p->next=NULL;
     }
    }
        system("cls");
    main_menu();
    return head;


}
/******************************************保存*********************************************************/
void save(stulink *head)
{
    FILE *fp;
    stulink *p;
    p=head;
    fp=fopen("d:\\mama.txt","wb");
       if(fp==NULL)
       {
        printf("保存失败");
        return;
       }
    while(head)
    {
        fwrite(p,sizeof(struct stulink*),1,fp);
        p=p->next;
    }
    fclose(fp);
    printf("保存成功");


}
void load(stulink *head)
{
    FILE *fp;
    stulink *p;
    fp=fopen("d:\\mama.txt","rb");
    if(fp==NULL)
    {
        printf("读取数据失败");
        return;
    }
    while(feof(fp))
    {
        ;
    }

}
/***************************全部的遍历*******************************************************************/
void printlink(stulink *head)
{
   
    system("cls");
    void main_menu();
    stulink *p;
    p=head;
    int a;
    if(head==NULL)
    {
        printf("暂无信息!\n");
    goto loop;
    }
    while(p)
    {
        puts("姓名\t数学\t计算机\tC语言\t英语");
        printf("%s\t%.1f\t%.1f\t%.1f\t%.1f\n",p->name,p->math,p->computer,p->c,p->english);
        p=p->next;
    }
loop:
    printf("按Q回到菜单\n");
    if (getch()=='q')
        main_menu();


}
/****************************成绩的遍历*******************************************************************/
void scoreinput(stulink *head)
{
    system("cls");
   
    void main_menu();
    stulink *p;
    p=head;
    while(p)
    {
        printf("%s\t\n",p->name);
        printf("math:");
        scanf("%f",&p->math);
        printf("computer:");
        scanf("%f",&p->computer);
        printf("c:");
        scanf("%f",&p->c);
        printf("english:");
        scanf("%f",&p->english);
        p=p->next;
    }
    save(head);
    main_menu();
}
/*************************************************目录区***********************************************/
void main_menu()
{
    system("cls");
    puts("1学生信息录入");
    puts("2学生成绩录入");
    puts("3课程信息录入");   
    puts("4查询");
    puts("5统计");
    puts("0退出");
}
void search_menu(stulink *head)
{
    puts("1全部信息现实");
    puts("2按学号查询");
    puts("3按姓名查询");   
    puts("4");
    puts("5");
    int option;
    while(1)
    {
    printf("请输入序号");
    scanf("%d",&option);
    switch (option)
    {
    case 0:break;
    case 1:printlink(head);break;
    case 2:break;
    case 3:break;
    case 4:break;
    case 5:break;
    }
    }

}
void tongji(stulink *head)
{
    puts("1各科平均分");
    puts("2学生平均分");
    puts("3不及格学生");   
    puts("4");
    puts("5");
    int option;
    while(1)
    {
    printf("请输入序号");
    scanf("%d",&option);
    switch (option)
    {
    case 0:break;
    case 1:;break;
    case 2:break;
    case 3:break;
    case 4:break;
    case 5:break;
    }
    }

}

/*******************************************************************************************************/
void pinjun(stulink *head)
{
    stulink *p;
    p=head;
    float mathsum=0.0,csum=0.0,comsum=0.0,engsum=0.0;
   
    while(p)
    {
        mathsum+=p->math;
        csum+=p->c;
        comsum+=p->computer;
        engsum+=p->english;


    }

}



void main ()
{
    int option;
    stulink *head=NULL;
    main_menu();

    while(1)
    {printf("请输入序号");
   
    scanf("%d",&option);
        
   
    switch (option)
    {
    case 0:exit(0);
    case 1:head=creat();break;
    case 2:scoreinput(head);break;
    case 3:break;
    case 4:search_menu(head);break;
    case 5:tongji(head);break;
    }
    }

   
   
}
/*******************************************************************************************************/
搜索更多相关主题的帖子: include computer system 
2012-12-24 17:16
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:20 
程序代码:
if(fp==NULL)
{
    printf("保存失败");
    return;
}
while(head)    //这里错了
{
    fwrite(p,sizeof(struct stulink*),1,fp);
    p=p->next;
}


[fly]存在即是合理[/fly]
2012-12-24 17:30
快速回复:保存出问题了不知道为什么
数据加载中...
 
   



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

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