<分区>
我正在尝试使用一个变量,并在函数使用它之后立即将其删除。 基本上我是 doint str1+str2,在函数中使用它,然后释放内存。 我以为我得到了一切,但我的代码抛出警告和错误:
- 错误:“命令”的重新定义。
- 警告:函数“malloc”的隐式声明[-Wimplicit-function-declaration]
- 警告:内置函数“malloc”的隐式声明不兼容[默认启用]
- 警告:函数'free'的隐式声明[-Wimplicit-function-declaration]
- 警告:内置函数“free”的隐式声明不兼容[默认启用]
这是前面提到的代码:
// Step 1
char* commande = (char*) malloc(len1 + len2 + 1);
strcpy(commande, str1);
strcat(commande, str2);
function(commande);
free(commande);
// Step 2
char* commande = (char*) malloc(len3 + len4 + 1);
strcpy(commande, str3);
strcat(commande, str4);
function(commande);
free(commande);
我做错了什么?
编辑:我更正了 len2 中的拼写错误。