导入库
#include<stdlib.h>
#include<string.h>
malloc()前一般有强制转换数据类型
静态申请:
char *p=(char *)malloc(sizeof(char)*20);
strcpy(p,“hello”);
printf("%s\n",p);
动态扩充:
char *q;
q=(char *)realloc(p,sizeof(char)*20); //p被清空,q包含p内容,p后再添20内存
strcat(q,"teacher"); //接在后面添加
printf("%s\n",q);
free(q); //释放内存