Cho em hỏi ở ts.loai tại sao phải dùng con trỏ là*ts.loai
if(ts.tong>19)
*ts.loai=“do”;
else
*ts.loai=“truot”;
mà không phải ts.loai. Nếu đung ts.loai thì phải sử dụng strcpy
if(ts.tong>19)
strcpy(ts.loai,”do”);
else
strcpy(ts.loai,”truot”);
Code đủ
#include<stdio.h>
#include<stdio_ext.h>
#include<string.h>
int main()
{
FILE *fp;
int i,n;
struct thisinh
{
char hoten[30],*loai[6];
float toan,ly,hoa,tong;
}ts;
printf("nhap so thi sinh=");
scanf("%d",&n);
fp=fopen("diem.dat","wb");
for(i=0;i<n;i++)
{
printf("nhap thong tin thi sinh thu %d\n",i+1);
printf("ho ten: ");
__fpurge(stdin);
gets(ts.hoten);
printf("diem toan");
scanf("%f",&ts.toan);
printf("diem ly");
scanf("%f",&ts.ly);
printf("diem hoa");
scanf("%f",&ts.hoa);
ts.tong=ts.toan+ts.ly+ts.hoa;
if(ts.tong>19)
*ts.loai="do";
else
*ts.loai="truot";
fwrite(&ts,sizeof(ts),1,fp);
}
fclose(fp);
fp=fopen("diem.dat","rb");
while(fread(&ts,sizeof(ts),1,fp)>0)
{
printf("%s %f %f %f %f %s\n",ts.hoten,ts.toan,ts.ly,ts.hoa,ts.tong,*ts.loai);
}
fclose(fp);
return 0;
}