|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 galaxy 于 2011-6-27 09:53 编辑
- #include<stdio.h>
- #define N 4
- struct student_type
- {
- char name[10];
- int num;
- int age;
- char addr[30];
- }stu[N];
- void save()
- {
- int i;
- FILE *fp;
-
- if( !( fp=fopen("stu_list.dat","wb") ) )
- {
- printf("Can not open the file!!\n");
- return;
- }
- for(i=0;i<N;i++)
- if( fwrite(&stu[i],sizeof(struct student_type),1,fp) !=1 );
- printf("write error\n");
- fclose(fp);
-
- }
- void main()
- {
- int i;
- printf("Please input the name num age and address\n");
- for(i=0;i<N;i++)
- scanf("%s%d%d%s",stu[i].name,&stu[i].num,&stu[i].age,stu[i].addr);
- save();
- }
- /*从键盘输入4个学生的成绩,然后以二进制形式储存到磁盘文件上*///总是报错 :write error 求助
复制代码
|
|