| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 682 人关注过本帖
标题:2级C求解
只看楼主 加入收藏
时光追不回1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2016-4-29
结帖率:0
收藏
 问题点数:0 回复次数:2 
2级C求解
#include<stdio.h>
#define N 5
typedef struct srudent
{
    long sno;
    char name[10];
    float score[3];
   
   
}STU;
void fun(char *filename,STU n)
{
    FILE *fp;
    fp =fopen(filename,"rb+");
    fseek (fp, -(long)sizeof(STU),SEEK_END);
    fwrite(&n,sizeof(STU),1,fp);
    fclose(fp);
   
}
main()
{
    STU t[N]={10001,"MaChao",91,92,77},
             {10002,"CaoKai",75,60,88},
             {10003,"LiSi",85,70,78},
             {10005,"ZhangSan",95,80,88};
    STU n ={10006,"ZhaoSi",55,70,68},ss[N];
    int i,j; FILE *fp;
    fp= fopen("student.dat","wb");
    fwrite(t,sizeof(STU),N,fp);
    fclose(fp);
    fp = fopen("student.dat","rb");
    fread(ss,sizeof(STU),N,fp);
    fclose(fp);
    printf("\nThe original data :\n\n");
    for (j =0;j<N;j++);
    {
        printf("%6.2F",ss[j].score[i]);
        printf("\n")
    }
    fun (student.dat,n);
    printf("\n Tne date after modifing :\n\n");
    fp =fopen("stundent.dat","rb");
    fread(ss,sizeof(STU),N,fp);
    fclose(fp);
    for(j=0;j<N;j++)
    {
        printf("\nNo: % ld Name: % -8sScores:",ss[j].sno,ss[j]name);
        for (i=0;i<3;i++)
        printf("6.2f",ss[j].score[i]);
        printf("\n");
        
    }         
}
这里怎么运行不了STU t[N]={10001,"MaChao",91,92,77},
             {10002,"CaoKai",75,60,88},
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: include 
2016-08-06 14:42
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:0 
#include<stdio.h>
#define N 5
typedef struct srudent
{
    long sno;
    char name[10];
    float score[3];
   
   
}STU;
void fun(char *filename,STU n)
{
    FILE *fp;
    fp =fopen(filename,"rb+");
    fseek (fp, -(long)sizeof(STU),SEEK_END);
    fwrite(&n,sizeof(STU),1,fp);
    fclose(fp);
   
}
main()
{
    STU t[N]={
                {10001,"MaChao",91,92,77},
             {10002,"CaoKai",75,60,88},
             {10003,"LiSi",85,70,78},
             {10005,"ZhangSan",95,80,88}
    };
    STU n ={10006,"ZhaoSi",55,70,68},ss[N];
    char Filename[]="student.dat";
    int i,j; FILE *fp;
    fp= fopen("Filename","wb");
    fwrite(t,sizeof(STU),N,fp);
    fclose(fp);
    fp = fopen("student.dat","rb");
    fread(ss,sizeof(STU),N,fp);
    fclose(fp);
    printf("\nThe original data :\n\n");
    for (j =0;j<N;j++);
    {
        printf("%6.2F",ss[j].score[i]);
        printf("\n");
    }
    fun (Filename,n);    //student.dat不是这样引用的吧。
    printf("\n Tne date after modifing :\n\n");
    fp =fopen("Filename","rb");
    fread(ss,sizeof(STU),N,fp);
    fclose(fp);
    for(j=0;j<N;j++)
    {
        printf("\nNo: % ld Name: % -8sScores:",ss[j].sno,ss[j].name);
        for (i=0;i<3;i++)
        printf("6.2f",ss[j].score[i]);
        printf("\n");
        
    }         
}
你算法上的错误你自己改吧
2016-08-06 15:42
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
以下是引用时光追不回1在2016-8-6 14:42:42的发言:

这里怎么运行不了STU t[N]={10001,"MaChao",91,92,77},
             {10002,"CaoKai",75,60,88},


    STU t[N]={10001,"MaChao",91,92,77},
             {10002,"CaoKai",75,60,88},
             {10003,"LiSi",85,70,78},
             {10005,"ZhangSan",95,80,88};
改为:
    STU t[N]={{10001,"MaChao",91,92,77},
             {10002,"CaoKai",75,60,88},
             {10003,"LiSi",85,70,78},
             {10005,"ZhangSan",95,80,88}};
2016-08-06 15:58
快速回复:2级C求解
数据加载中...
 
   



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

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