c语言文件
#include <stdio.h>#define SIZE 4
struct student_type
{
char name[10];
int num;
int age;
char addr[15];
}stud[SIZE];
void save()
{
FILE * fp;
int i;
if((fp=fopen("stu_list.txt","wb"))==NULL)
{
printf("can not open file\n");
return;
}
for(i=0;i<SIZE;i++)
{
if(fwrite(&stud[i],sizeof(struct student_type),1,fp)!=1)
{
printf("file write error\n");
}
}
fclose(fp);
}
void main()
{
int i;
for(i=0;i<SIZE;i++)
{
scanf("%s%d%d%s",stud[i].name,&stud[i].num,&stud[i].age,stud[i].addr);
}
save();
}
输入 Zhang 1001 19 room.1
Fun 1002 20 room.2
Tan 1003 21 room.3
ling 1004 22 room.4
后结果是zhang ? room.1 fun ? room.2 tan ? room.3 ling ? room.4 呢?