主函数文件
#include <stdio.h>
#include "testfunc.h"
int main(int argc, const char *argv[])
{
Student Stu[100];
Teacher Tec[100];
int choose,num = 0,Tnum = 0;
while(1){
printf("--------------------------------\n");
printf("--------1.输入学生信息----------\n");
printf("--------2.输入老师信息----------\n");
printf("--------3.遍历学生信息----------\n");
printf("--------4.遍历老师信息----------\n");
printf("--------5.退出------------------\n");
printf("--------------------------------\n");
printf("请输入序号>>>");
scanf("%d",&choose);
getchar();
switch(choose){
case 1:
insertStumsg(Stu,&num);
printf("%d %d\n",num,__LINE__);
break;
case 2:
insertTecmsg(Tec,&Tnum);
printf("%d %d\n",Tnum,__LINE__);
break;
case 3:
showStumsg(Stu,&num);
break;
case 4:
showTecmsg(Tec,&Tnum);
break;
case 5:
goto END;
break;
default:
printf("输入错误,请重新输入:");
}
}
END:
return 0;
}
函数文件
/*
* function: 输入学生信息
* @param [ in]
* @param [out]
* @return
*/
#include <stdio.h>
#include "testfunc.h"
void insertStumsg(Student* pStu,int *pnum)
{
printf("请输入学生的ID>>>\n");
scanf("%d",&((pStu + *pnum)->id));
getchar();
printf("请输入学生的姓名>>>\n");
scanf("%s",((pStu + *pnum)->name));
getchar();
printf("请输入学生的成绩>>>\n");
scanf("%f",&((pStu + *pnum)->t.score));
getchar();
(*pnum)++;
return;
}
void insertTecmsg(Teacher* pTec,int *pnum)
{
printf("请输入老师的ID>>>\n");
scanf("%d",&((pTec + *pnum)->id));
getchar();
printf("请输入老师的姓名>>>\n");
scanf("%s",((pTec + *pnum)->name));
getchar();
printf("请输入老师的绩效>>>\n");
scanf("%d",&((pTec + *pnum)->t.jixiao));
getchar();
(*pnum)++;
return;
}
void showStumsg(Student* pStu,int *pnum)
{
for(int i = 0;i<*pnum;i++)
{
printf("%d %s %g\n",(pStu + i)->id,\
(pStu + i)->name,(pStu + i)->t.score);
}
}
void showTecmsg(Teacher* pStu,int *pnum)
{
for(int i = 0;i<*pnum;i++)
{
printf("%d %s %d\n",(pStu + i)->id,\
(pStu + i)->name,(pStu + i)->t.jixiao);
}
}
头文件
#ifndef __FUN_H__
#define __FUN_H__
typedef union
{
int jixiao;
float score;
}Test;
typedef struct
{
int id;
char name[20];
Test t;
}Student;
typedef struct
{
int id;
char name[20];
Test t;
}Teacher;
void insertStumsg(Student* ptr,int *pnum);
void insertTecmsg(Teacher* ptr,int *pnum);
void showStumsg(Student* pStu,int *pnum);
void showTecmsg(Teacher* pStu,int *pnum);
#endif