将内存分配给**

时间:2016-05-20 01:00:57

标签: c

我有这个结构

typedef struct{
 char **palavras;
}no;

我想基本上为这个字符串数组分配内存

而且我无法做到这一点,因为它表示它会在'之前预期一些事情('

no *atual;

atual->(*palavras)=calloc(1,sizeof(char*));

2 个答案:

答案 0 :(得分:2)

您需要分几个阶段完成:

  • 首先,将内存分配给atual
  • 接下来,将内存分配给palavras
  • 最后,将内存分配给palavras
  • 的元素

假设你需要分配10 palavras,你可以这样做:

no *atual = malloc(sizeof(no));
atual->palavras = malloc(sizeof(char*)*10);
atual->palavras[0] = malloc(20);
...

答案 1 :(得分:-1)

您应该palavras访问atual->palavras,例如atual->palavras = calloc(5, sizeof(char *))char ** *atual->palavras取消引用char *。您也可以atual->palavrasatual->palavras[0] = malloc(10 * sizeof(char))指针分配内存,例如# To remove trailing slash RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ $1 [R=301,L] # To remove .php extension RewriteRule ^(.*)\.php$ $1 [R=301,L] # To check whether the file exists then set it back internally RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.php -f RewriteRule ^.*$ $0.php [L]