Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.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,以下代码将数组作为参数从主进程(称为process)传递到另一个进程(称为subprocess)。它模拟我想在自己的代码中实现的行为:子流程用正确的字符串填充字符串数组,然后将它们返回到流程,以便。。。处理 #include <stdio.h> #include <string.h> void preprocess(char input[10][10]) { int i; char temp[10]; for (i = 0

以下代码将数组作为参数从主进程(称为
process
)传递到另一个进程(称为
subprocess
)。它模拟我想在自己的代码中实现的行为:
子流程
用正确的字符串填充字符串数组,然后将它们返回到
流程
,以便。。。处理

#include <stdio.h>
#include <string.h>

void preprocess(char input[10][10]) {
        int i;
        char temp[10];
        for (i = 0; i < 10; i++) {
                scanf("%s", &temp);
                strcpy(input[i], temp);
        }
}

void process() {
        int i;
        char strings[10][10];
        preprocess(strings);
        for (i = 0; i < 10; i++) {
                printf("%s\n", strings[i]);
        }
}

int main() {
        process();
        return 0;
}
你应使用:

scanf("%s", temp);
不是


传递给
scanf
的参数不正确。
%s
格式说明符需要指向
字符数组的第一个元素的指针。您传入的是数组的地址

scanf
呼叫中删除操作员
&
的地址。当数组传递给函数时,它将衰减为指向第一个元素的指针

scanf("%9s", temp);

格式说明符中的数字给出了要读取的最大字符数。这可以防止潜在的缓冲区溢出
temp

警告是什么?@Paul这与scanf期望的参数类型有关-它应该是char*而不是char(*)[10]。还有,人们为什么会否决正确、诚实的问题-_-可能是因为你的问题中没有包含警告,所以没有人知道你有什么问题。@PaulGriffiths很公平。:/对于一个新用户来说,在这么小的事情上受到沉默的否决票是非常令人恼火的——这不是声誉,而是蔑视。这不是小事——如果一个关于删除警告的问题实际上没有包含警告,那么这个问题是严重的错误。如果你编辑你的问题来改进它,你很可能会得到一些选票。
scanf("%s", &temp);
scanf("%9s", temp);