- 论坛徽章:
- 0
|
引用:
#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("stud_list","wb" )==NULL)
{printf("cannot open file\n" ;
return;
}
for(i=0;i<SIZE;i++)
**if(fwrite(&stud,sizeof(struct student_type),1,fp)!=1)**
printf("file write Eorre\n" ;
fclose(fp);
}
main()
{
int i;
for(i=0;i<SIZE;i++)
scanf("%s%d%d%s,stud.name,&stud.num,&stud.age,stud.addr)
save();
}
问题1:打星号的部分只是一个判断语句,书上却说它已经把结构体的内容输出到了"stu_list"文件中判断语句也能做实际操作吗?而且这个操作还能保存吗?
请教各位!
问题2: if((fp=fopen("stud_list","wb" )==NULL)
{printf("cannot open file\n" ;
return;
}
上面的if语句也是在做判断啊!能真正打开文件吗?
如果真的要打开应该调用
fopen((fp=open("stu_list","wb" ;
才对啊?? |
|