#include
#define SIZE 10
struct Student_type //定义结构体数组stud,包含10个学生数据
{
char name[10];
int num;
int age;
char addr[15];
}stud[SIZE];
void save()
{
FILE*fp;
int i;
if((fp=fopen("E:\\stu.txt","wb"))==NULL)
{
printf("can not open file\n");
return 0;
}
for (i=0;i if(fwrite(&stud[i],sizeof(struct Student_type),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
int main()
{
int i;
printf("please enter data of students:\n");
for(i=0;i scanf("%s,%d,%d,%s",&stud[i].name,&stud[i].num,&stud[i].age,&stud[i].addr);
save();
return 0;
}
阅读(763) | 评论(0) | 转发(0) |