#include
#define SIZE 10
struct Student_type
{char name;
int num;
int age;
char addr[15];
}stud[SIZE];
void save()
{FILE *fp;
int i;
if((fp=fopen("stud.dat","wb"))==NULL)
{printf("connot open this file\n");
return;
}
for(i=0;i
printf("file write error\n");
fclose(fp);
}
int main()
{int i;
printf("Please enter data of students:\n");
for(i=0;i
save();
return 0;
}
之后再用这个程序
#include
#include
#define SIZE 10
struct Student_type
{char name[10];
int num;
int age;
char addr[15];
}stud[SIZE];
int main()
{int i;
FILE *fp;
if((fp=fopen("stud.dat","rb"))==NULL)
{printf("cannot open file\n");
exit(0);
}
for(i=0;i
printf("%-10s %4d %4d %-15s\n",stud[i].name,stud[i].num,stud[i].age,stud[i].addr);
}
fclose(fp);
return 0;
}
但是cmd显示的是connt open file
为什么呢?是程序除了问题吗?求解