结构体包含二级指针和二级指针内存的申请与释放问题

#define _CRT_SECURRE_NO_WARNINGS
#include
#include
#include 

typedef struct Teacher 
{
	char name[20];//20 内存块 已分配
	int age;//4
	char *alisname;//4 只分配4个字节的内存 
	char **stunames;//规定一个研究生导师带4名学生
	
}Teacher;


void printTeacher(Teacher *arr,int num)
{
	int i;
	for (i=0;iarr[j].age)
			{
				tmp = arr[i];
				arr[i] = arr[j];
				arr[j] = tmp;
			}
		}
	}
}
//通过函数参数返回
int createTeacher2(Teacher**tea,int Tnum,int Snum )
{
	Teacher *tmp;
	int ret = 0,i,j;
	char **p=NULL;
	tmp =(Teacher*)malloc(sizeof(Teacher)*Tnum);
	//printf("sizeof(Teacher):%d\n",sizeof(Teacher));//
	if (tmp == NULL)
	{
		ret = -1;
		return ret;
	}
	memset(tmp,0,sizeof(Teacher)*Tnum);
	for (i=0;i

你可能感兴趣的:(C语言提高)