下面代码哪里出错了啊。。也不报错,就是没有结果
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define N 3
float RAND(int, int);
struct stu{
char name[7];
float height;
float weight;
float score;
} body[N],a,*pb;
int main(void){
pb = body;
FILE *fp;
int i;
if((fp = fopen("dome.txt","wb+"))==NULL){
puts("dome.txt文件打开失败!\n");
exit(1);
}
puts("请输入姓名:");
for(i=0;i<N;i++,pb++){
scanf("%s",pb->name);
}
puts("请输入身高,体重,成绩:");
puts("\n");
for (i = 0;i< N; i++,pb++){
pb->height = RAND(160,185);
pb->weight = RAND(50, 100);
pb->score = RAND(90, 100);
}
fwrite(body, sizeof(struct stu), N, fp);
fseek(fp, sizeof(struct stu), SEEK_SET);
fread(&a, sizeof(struct stu), 1, fp);
printf("姓名:%s\n身高:%f\n体重:%f\n成绩:%f\n", a.name,a.height,a.weight,a.score);
fclose(fp);
return 0;
}
float RAND(int a, int b){
float x;
srand((unsigned)time(NULL) + rand());
x = rand() % (b - a + 1) + a;
return x;
}