我回去给你搞搞 我现在这里没VC
#include<stdio.h>
#define N 100
typedef struct student
{
char a[10];
float d;
float b;
float c;
}stu;
void add(stu *s)
{
stu *p;
int i;
FILE *fp;
p=s;
if((fp=fopen("f:\\read.txt","a+"))==NULL)
{
printf("cannot open the file!\n");
return;
}
for(i=0;i<N;i++)
if(fwrite(p,sizeof(struct student),1,fp)!=1)
printf("file write error!\n");
rewind(fp);
fclose(fp);
}
void shuchu(stu *s)
{
FILE *fp;
int i;
fp=fopen("f:\\read.txt","r");
while(1)
{
fread(s,sizeof(struct student),1,fp);
printf("%-s %-f %-f %-f \n",s->a,s->d,s->b,s->c);
if (feof(fp))
{
break;
}
}
fclose(fp);
}
void main()
{
stu s;
int i;
printf("请输入数据:\n");
for(i=0;i<N;i++)
scanf("%s %f %f %f",s.a,&(s.d),&(s.b),&(s.c));
add(&s);
shuchu(&s);
}
这个你试试