Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 多个字符串的空间分配_C_Arrays_Pointers - Fatal编程技术网

C 多个字符串的空间分配

C 多个字符串的空间分配,c,arrays,pointers,C,Arrays,Pointers,嗨,我想找一个空间来储存一些单词。 我的计划是使用一个二维数组,它存储一个字符串。 看起来是这样的: pBuffer[0]---------->myBuffer[0][0] myBuffer[0][1]... pBuffer[1]---------->myBuffer[1][0] myBuffer[1][1]... .. 然而,它会出错,我正在努力调试它。 有什么问题吗 1.宣言 2.用法 3.错误与警告 因为你写了一些奇怪的东西。它应该是pBuffer[i]=&myBuffer[

嗨,我想找一个空间来储存一些单词。 我的计划是使用一个二维数组,它存储一个字符串。 看起来是这样的:

pBuffer[0]---------->myBuffer[0][0] myBuffer[0][1]...
pBuffer[1]---------->myBuffer[1][0] myBuffer[1][1]...
..
然而,它会出错,我正在努力调试它。 有什么问题吗

1.宣言 2.用法 3.错误与警告
因为你写了一些奇怪的东西。它应该是
pBuffer[i]=&myBuffer[i][0],当然是循环。

因为你写了一些奇怪的东西。它应该是
pBuffer[i]=&myBuffer[i][0],当然是在循环中

char* pBuffer[i] = &myBuffer[i][0];
去掉前导的“char*”,编译器认为您试图声明一个名为pBuffer的新变量,它“隐藏”了pBuffer的原始定义

char* pBuffer[255]; // declares pbuffer as an array of 255 char* pointers
char* pBuffer[i];   // illegal and, if it worked, would be a shadow declaration.
去掉前导的“char*”,编译器认为您试图声明一个名为pBuffer的新变量,它“隐藏”了pBuffer的原始定义

char* pBuffer[255]; // declares pbuffer as an array of 255 char* pointers
char* pBuffer[i];   // illegal and, if it worked, would be a shadow declaration.

输入完整的代码,请更新您的帖子。输入完整的代码,请更新您的帖子。如果您使用的是略显现代的C版本(不是23岁以上的版本,而是13岁以上的版本-C99,或更新的C11),则使用
char*pBuffer[i]声明是一个有效的VLA(可变长度数组)定义,假设
i
是一个整数变量(或整数常量的名称,但它不再是VLA)。但是,正如编译器错误消息所示,您不能为VLA提供任何初始值设定项声明是一个有效的VLA(可变长度数组)定义,假设
i
是一个整数变量(或整数常量的名称,但它不再是VLA)。但是,正如编译器错误消息所示,您不能为VLA提供任何初始值设定项。
char* pBuffer[i] = &myBuffer[i][0];
char* pBuffer[255]; // declares pbuffer as an array of 255 char* pointers
char* pBuffer[i];   // illegal and, if it worked, would be a shadow declaration.