C程序编译不通过,帮忙看一下是哪里的问题.

来源:百度知道 编辑:UC知道 时间:2024/05/21 06:46:56
#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","wb"))==NULL)
{
printf("cannot 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)
}

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();
}
}

fclose(fp)
后面要加分号

(试试看是不是你想要的)
#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","wb"))==NULL)
{
printf("cannot 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();
}
}

编译器报的啥错误?