//第3题
#include
#include
int main(void)
{
char f_name[24];
char str[100];
printf("please enther the file name:");
scanf("%s",str);
sprintf(f_name,"%s.txt",str);
FILE *fp=fopen(f_name,"w+");
printf("please enther the string:");
scanf("%s",str);
fprintf(fp,"%s%d",str,strlen(str));
return 0;
}
//第4题
#include
#include
#include
typedef struct {
int num;
char name[20];
int math;
int chin;
int eng;
int avg;
}student;
void cal_avg(student *stu)
{
int i=0;
for (i;i<5;i++)
{
stu[i].avg=(stu[i].chin+stu[i].math+stu[i].eng)/3;
}
}
int output(student *stu)
{
FILE *fp=fopen("stud.txt","w+");
if (fp==NULL)
{
printf("can't open file!");
return -1;
}
fwrite(stu,sizeof(student),5,fp);
return 1;
}
void input(student *stu)
{
int i=0;
for (i;i<5;i++)
{
stu[i].num=i+1;
printf("please enther the %dth student's name:",i+1);
scanf("%s",stu[i].name);
printf("please enther the %dth student's math grade:",i+1);
scanf("%d",&stu[i].math);
printf("please enther the %dth student's chin grade:",i+1);
scanf("%d",&stu[i].chin);
printf("please enther the %dth student's eng grade:",i+1);
scanf("%d",&stu[i].eng);
printf("/********************************************/\n");
}
}
int main(void)
{
student stu[5];
input(stu);
cal_avg(stu);
output(stu);
return 0;
}