在下面的代码中,我想将'pre'中的字符串复制到数组'word',以便稍后可以打印数组'word',但它显示NONPORTABLE CONVERSION错误。尝试使用strcpy()做它,但它的功能。做任何其他方式?我想它生成的每一次出现在“前”的字符串存储到一个数组..将字符指针分配给字符指针数组
void print(char *pre,struct dic * root,int depth)
{
int i=0,flag=0,int j=0;
char *word;
for(;i<27;i++)
{
if(root->node[i])
{
pre[depth]='a'+i;
flag=1;
print(pre,root->node[i],depth+1);
pre[depth]=0;
}
}
if(flag == 0)
{
pre[depth]=0;
printf("\n%s\n",pre);
//j is declared globally
***word[j]=pre;***
//printf("\nWord[%d]=%s\n",j,word[j]);
}
}
谢谢。
啊,我重新阅读(在提交后立即),并看到代码底部的注释行。 @Matthieu是对的, static char **单词; 是你想要的,malloc()/ realloc()对于原始字符串数组以及每个strcpy()所需的字符串都是必需的。请注意,如果您每次调用该函数时都将此数组构建到该数组上(如果仅在该函数中需要它),它应该是静态的。 – Crwth 2010-08-05 20:06:26