我试图计算用于存储“ res”的数组的数组的元素,这些内存用于连接存储在“ argv”中的每个字符串,包括NULL终止符。可能会发现更多错误,但是我不了解的第一个错误是argv[a][b] != NULL
在中/* length of arrays */
。为什么这是不可接受的,还有其他方法(没有硬编码或传递长度)来确定元素数量?
使用的:http://pythontutor.com/c.html#mode=edit
char *ft_concat_params (int argc, char **argv)
{
int len_argc = argc - 1,
len_argv = 0;
char *res = NULL;
/* length of argvs */
for (int a = 0; a < len_argc; a++) {
for (int b = 0;argv[a][b] != NULL; b++) {
len_argv++;
}
}
/* allocate memory res -- freed by calling function! */
res = malloc (len_argv * sizeof …
Run Code Online (Sandbox Code Playgroud)