main函数接收子函数处理的数组,遍历数组时异常示例代码:#include#include#includevoiddemo(char*list[]){inti;charname[10];for(i=0;i
2 回答
烙印99
TA贡献1829条经验 获得超13个赞
list=(char**)malloc(sizeof(char));listonlypointtoamemoryareawhosesizeisonechar,that'sfarmorefromenough.ItwillcausesegmentfaultThesolutionistoallocateenoughforlist:constintN=200;//Nisthemaximuxlengthofeachstringchar**list=malloc(len*sizeof(char*));//Allocaterowpointersfor(i=0;i{ list[i]=malloc(N*sizeof(char));}...//don'tforgetfree!for(i=0;i{ free(list[i]);}free(list);BTW,thearrayallocatedwiththeformofmallocisnot可变数组(variablelengtharray).
添加回答
举报
0/150
提交
取消