#include
#include
#define NAME_MAX 10
#define NUMBER_MAX 10
#define STUDENTS_MAX 5
#define CLEAR_ENTER(array) for(int idx=0;array[idx]!='\0';idx++)\
if(array[idx]=='\n')\
array[idx]='\0';
typedef unsigned int Uint32;
typedef struct stu
{
char name[NAME_MAX];
char stu_number[NUMBER_MAX];
Uint32 chinese;
Uint32 math;
Uint32 english;
} stu;
int main(void)
{
stu students[STUDENTS_MAX];
int idx=0;
printf("输入5个学生的信息\n");
for(idx=0;idx{
printf("name:");
fgets(students[idx].name,NAME_MAX,stdin);
printf("number:");
//fgets(students[idx].stu_number,NUMBER_MAX,stdin);
fgets(students[idx].stu_number,NUMBER_MAX,stdin);
printf("三项分数(语文,数学,英语):");
scanf("%d%d%d",&students[idx].chinese,&students[idx].math,&students[idx].english);
getchar();
}
FILE * fp = fopen("stu.txt","w+");
if(!fp)
return -1;
for(idx=0;idx{
printf("name:%s\nnumber:%s\nchinese:%d\nmath:%d\nenglish:%d\n",students[idx].name,
students[idx].stu_number,
students[idx].chinese,
students[idx].math,
students[idx].english);
fprintf(fp,"name:%s\nnumber:%s\nchinese:%d\nmath:%d\nenglish:%d\n",students[idx].name,
students[idx].stu_number,
students[idx].chinese,
students[idx].math,
students[idx].english);
}
system("pause");
return 0;
}
简单的写了一个,没有调试过。编译通过,Mingw3.4.7.
#include
int main()
{
void aver(float *p,int n,int m);
int i,j;
float score[5][3];float *p;
p=score[0];
for(i=0;i<5;i++)
{
printf("请输入第%d学生的三门课程的成绩:\n",i+1);
for(j=0;j<3;j++)
scanf("%f\n",&score[i][j]);
}
aver(p,5,3);
}
void aver(float *p,int n,int m)
{
float sum;
int i,j;
for(i=0;i
for(j=0;j
printf("\n第%d个学生平均成绩:%5.2f\n",i+1,sum/m);
}
}
#include "stdio.h"
struct student
{ char num[6];
char name[8];
int score[3];
float avr;
} stu[5];
main()
{int i,j,sum;
FILE *fp;
/*input*/
for(i=0;i<5;i++)
{ printf("\n please input No. %d score:\n",i);
printf("stuNo:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
sum=0;
for(j=0;j<3;j++)
{ printf("score %d.",j+1);
scanf("%d",&stu[i].score[j]);
sum+=stu[i].score[j];
}
stu[i].avr=sum/3.0;
}
fp=fopen("stud","w");
for(i=0;i<5;i++)
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}