C 变量类型的系统wget
所以,我有几个url存储在一个名为url的字符指针数组中 我想在每个url上调用wget,但我一直得到以下错误C 变量类型的系统wget,c,wget,C,Wget,所以,我有几个url存储在一个名为url的字符指针数组中 我想在每个url上调用wget,但我一直得到以下错误 invalid operands to binary + (have 'char *' and 'char *') 我的程序是C语言的 system("wget" + url[0]); 在C语言中,不能使用+运算符连接两个字符串。改为使用strncat: NAME strcat, strncat - concatenate two strings SYNOPSIS
invalid operands to binary + (have 'char *' and 'char *')
我的程序是C语言的
system("wget" + url[0]);
在C语言中,不能使用
+
运算符连接两个字符串。改为使用strncat:
NAME
strcat, strncat - concatenate two strings
SYNOPSIS
#include <string.h>
char *strcat(char *dest, const char *src);
char *strncat(char *dest, const char *src, size_t n);
DESCRIPTION
The strcat() function appends the src string to the dest string, over‐
writing the null byte ('\0') at the end of dest, and then adds a termi‐
nating null byte. The strings may not overlap, and the dest string
must have enough space for the result.
The strncat() function is similar, except that
* it will use at most n characters from src; and
* src does not need to be null-terminated if it contains n or more
characters.
As with strcat(), the resulting string in dest is always null-termi‐
nated.
If src contains n or more characters, strncat() writes n+1 characters
to dest (n from src plus the terminating null byte). Therefore, the
size of dest must be at least strlen(dest)+n+1.
名称
strcat,strncat-连接两个字符串
提要
#包括
char*strcat(char*dest,const char*src);
char*strncat(char*dest,const char*src,size\u t n);
描述
函数的作用是:在
在dest末尾写入空字节('\0'),然后添加一个termi‐
本机为空字节。字符串不能重叠,而dest字符串
必须有足够的空间来显示结果。
strncat()函数与之类似,只是
*最多使用src中的n个字符;和
*如果src包含n或更多,则不需要以null结尾
人物。
与strcat()一样,dest中的结果字符串始终为null termi‐
内化。
如果src包含n个或更多字符,则strncat()将写入n+1个字符
到dest(src中的n加上终止的空字节)。因此,
目的地的大小必须至少为strlen(目的地)+n+1。
谷歌搜索“strncat”将为您提供大量关于如何使用它的示例。在C语言中,
+
操作符对字符串不起作用。要连接两个字符串并将结果传递给system()
,可以执行以下操作:
char buffer[ENOUGH_SPACE_TO_HOLD_CONCATENATED_RESULT]; /* Destination buffer for our command */
snprintf(buffer, sizeof(buffer), "wget %s", url[0]); /* You can also use strcat and friends for this step */
system(buffer); /* Now execute it */
我认为c不支持这种连接。您应该使用
系统(strcat(“wget”,url[0])
。codeomnitrix,您的代码调用UB-strcat
希望目标缓冲区有足够的空间来追加源代码。你能改为编辑它或把它转换成答案吗?