#include <stdio.h>
#include <stdlib.h>
int config_read(char * filep, char *** p, int * len) {
printf(“config file name is :%s\n”, filep);
char ** tempP = (char**)malloc(sizeof(char *)*10);
for(int i =0; i<10; i++) {
tempP[i] = (char *)malloc(20);
sprintf(tempP[i],"%d%d%d",i,i,i);
}
*p = tempP;//*p实参的地址 放在 = 的左边 去间接修改实参的值
*len = 10;
return 0;
}
int config_read_free1(char ** p, int * len) {
if (p == NULL) {
return -1;
}
for(int i = 0; i<10; i++) {
free(p[i]);
}
free§;
return 0;
}
int config_read_free2(char *** p, int * len) {
config_read_free1(*p, len);
p == NULL;
return 0;
}
int main() {
char **myP = NULL;
int mylen = 0;
char * myfilep= "./1.txt";
config_read(myfilep,&myP,&mylen);
for(int i = 0; i < 10; i++) {
printf("myP[%d]:%s\n",i,myP[i]);
}
//config_read_free1(myP,&mylen);
config_read_free2(&myP,&mylen);
return 0;
}