本文共 1134 字,大约阅读时间需要 3 分钟。
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
int insertStudentInfo(Class * pClass, int index, Student * student)//定义函数insertStudentInfo(将信息插入班级)
{
int i = 0; //定义整型变量i
if(pClass->count >= STUDENTMAXCOUNT) //判断删除位置是否合法
{
printf("\n\n学生信息数量不能超过%d个\n\n",STUDENTMAXCOUNT);//输出“学生信息数量不能超过%d个”
return 0;
}
if(index < 0 || index > pClass->count) //判断位置是否合法
{
printf("\n\n插入位置不合理\n\n"); //输出“插入位置不合理”
return 0;
}
for(i = pClass->count; i > index; i--)
{
pClass->students[i] = pClass->students[i-1];
}
pClass->students[index] = (Student *)malloc(sizeof(Student));//向系统申请分配size个字节的内存空间以输入pClass->students[index]
*(pClass->students[index]) = *student;
pClass->count++;
printf("\n\n插入操作成功。\n\n\n");
return 1;
} int deleteStudentInfo(Class * pClass, int index, Student * student)//定义函数deleteStudentInfo(删除班级中信息)
{
int i=0; //定义整型变量i
if(index < 0 || index > pClass->count - 1) //判断删除位置是否合法
{
printf("\n\n删除位置不合法\n\n"); //输出“删除位置不合法”
return 0;
}
*student = *(pClass->students[index]);
free(pClass->students[index]); //将申请内存还回
for(i = index; i < pClass->count - 1;i++)
pClass->students[i] = pClass->students[i + 1];
pClass->count--;
printf("\n\n删除执行成功\n\n\n");
return 1;
}
转载地址:http://oxdko.baihongyu.com/