关于 FILE

来源:百度知道 编辑:UC知道 时间:2024/05/06 15:34:22
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;

void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxu

ab+是指以可读写方式打开文件
gets(temp)读取字符串,也就是你输入的数字,并存放到temp所指向的内存内

data.score[0]=atof(temp); 把字符串转化为 float 型变量存入data.score[0]

gets(temp); 表示读取一个字符串,比如你输入的成绩
data.score[0]=atof(temp); atof(temp)表示把字符串转化为float