Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.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 - Fatal编程技术网

向C中的数组添加值不会';行不通

向C中的数组添加值不会';行不通,c,arrays,C,Arrays,我想将字符串添加到字符串数组,但它不起作用。 目前,我有以下代码: void splitArray(char *strings, char *delimiter) { int i = 0; char newArray[MAXCHARS]; char* pch = NULL; pch = strtok(strings, delimiter); while (pch != NULL) { // doesn't work; Exception: warning: assignment ma

我想将字符串添加到字符串数组,但它不起作用。
目前,我有以下代码:

void splitArray(char *strings, char *delimiter) {
int i = 0;
char newArray[MAXCHARS];
char* pch = NULL;

pch = strtok(strings, delimiter);

while (pch != NULL)
{
    // doesn't work; Exception: warning: assignment makes integer from pointer without a cast [enabled by default]
    newArray = pch;
    printf("%s\n", pch);
    pch = strtok(NULL, delimiter);
}
}

如何解决该问题?

使用strcpy将字符串复制到char数组。

通过
strcpy
将pch复制到新数组中?顺便说一下,
charnewarray[MAXCHARS]
不是一个字符串数组,它是一个字符数组-也称为字符串…谢谢你解决了这个问题Good:)在这种情况下你应该接受@cloud1的答案,因为他说的基本上是一样的。为什么在函数返回时数组丢失时向数组添加一些东西?你到底想达到什么目的?(顺便说一句,您没有字符串数组)参数应该是字符串数组,然后我用分隔符将其拆分。之后,我想将分割的数组返回主程序