#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
typedef struct Teacher
{
//char student[10][30]
char name[64];
char *alisname;
char **stuname;
int age ;
int id;
}Teacher;
int createTeacher02(Teacher **pT, int num)
{
int i = 0, j = 0;
Teacher * tmp = NULL;
tmp = (Teacher *)malloc(sizeof(Teacher) * num); // Teacher Array[3]
if (tmp == NULL)
{
return -1;
}
memset(tmp, 0, sizeof(Teacher) * num);
for (i=0; i<num; i++)
{
char **p = NULL;
//malloc一级指针
tmp[i].alisname = (char *)malloc(60);
//二级指针的第三种内存模型
p = (char **)malloc(3 * sizeof(char *)); //打造二维内存
for (j=0; j<3; j++)
{
p[j] = (char *)malloc(120);
}
tmp[i].stuname = p; //
}
malloc(sizeof(char *)*n)模型
最新推荐文章于 2021-11-08 22:20:59 发布