又出问题了!!!!
#include <stdio.h>
#define N 10
struct student
{char num[10];
char name[8];
int score[2];
float ave[10];
}st[N],temp;
main()
{
FILE *fp;
int i,j,n;
if((fp=fopen("student","r"))==NULL)
{printf("Can not open the file.");
exit(0);
}
printf("\nfile'student':");
for(i=0;i<10;i++)
{fscanf(fp,"%s,%s",&st[i].num,&st[i].name);
for(j=0;j<2;j++)
fscanf(fp,"%8d",st[i].score[j]);
fscanf(fp,"%10.2f",st[i].ave);
}
fclose(fp);
n=i;
for(i=0;1<n;i++)
for(j=i+1;j<n;j++)
if(st[i].ave<st[j].ave)
{temp=st[i];
st[i]=st[j];
st[j]=temp;
}
printf("\nnow:");
fp=fopen("score","w");
for(i=0;i<n;i++)
{fwrite(&st[i],sizeof(struct student),1,fp);
printf("\n%8s%8",st[i].num,st[i].name);
for(j=0;j<2;j++)
printf("%8d",st[i].score[j]);
printf("%10.2f",st[i].ave);
}}
程序运行后没有结果?
问题点数:50、回复次数:3Top
1 楼songsong33(天堂里的蚊子)回复于 2005-07-01 00:44:06 得分 0
markTop
2 楼foochow(无聊,灌水......)回复于 2005-07-01 00:47:56 得分 0
什么东东啊~连个注释都没:-)Top
3 楼gogdo(草草)回复于 2005-07-01 01:39:09 得分 0
#include <stdio.h>
#include <stdlib.h>
#define N 10
struct student
{
char num[10];
char name[8];
int score[2];
float ave[10];
}st[N],temp;
void main()
{
FILE *fp;
int i,j,n;
if((fp=fopen("student","r"))==NULL)
{
printf("Can not open the file.");
exit(0);
}
printf("\nfile'student':");
for(i=0;i<10;i++)
{
fscanf(fp,"%s,%s",&st[i].num,&st[i].name);
for(j=0;j<2;j++)
fscanf(fp,"%8d",st[i].score[j]);
fscanf(fp,"%10.2f",st[i].ave);
}
fclose(fp);
n=i;
for(i=0;1<n;i++)
for(j=i+1;j<n;j++)
if(st[i].ave<st[j].ave)
{
temp=st[i];
st[i]=st[j];
st[j]=temp;
}
printf("\nnow:");
fp=fopen("score","w");
for(i=0;i<n;i++)
{
fwrite(&st[i],sizeof(struct student),1,fp);
printf("\n%8s%8",st[i].num,st[i].name);
for(j=0;j<2;j++)
printf("%8d",st[i].score[j]);
printf("%10.2f",st[i].ave);
}
}
我的VC6.0下能运行的啊!
可能是你没有包含#include <stdlib.h>库文件.
Top




