且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从char *转换为char **

更新时间:2022-05-12 05:50:10

您已将strArray定义为char*的数组(即,指向字符串的指针),但是分配的大小为N *单个字符.我怀疑你的意思是
You have defined strArray as an array of char* (i.e. pointers to character strings) but your allocation is of N * the size of a single character. I suspect what you meant was
char ** strArray = (char **)malloc(N * sizeof(char*));


然后,您可以使用诸如
的分配


Then you could use an assignment such as

strArray[1] = str;  // save the address of this string to strArray


是的....我在那里犯了一个可怕的错误.谢谢帕里尼(Thanx Pallini).
Yes....I made a terrible mistake there. Thanx Pallini.