你好我尝试在PHP两个字符串之间添加一个空格,strcopy它们放入一个变量在C上两个字符串之间添加空间
,我们可以只用一个+
front_name = "hello";
back_name = "world";
full_name = strcpy(m[index].p.something, front_name + " " + backname);
// should output hello world
是什么将它们添加相当于还是以正确的方式在c中完成它?
你好我尝试在PHP两个字符串之间添加一个空格,strcopy它们放入一个变量在C上两个字符串之间添加空间
,我们可以只用一个+
front_name = "hello";
back_name = "world";
full_name = strcpy(m[index].p.something, front_name + " " + backname);
// should output hello world
是什么将它们添加相当于还是以正确的方式在c中完成它?
sprintf的将是理想的条件是所述字符串被复制到缓冲区是大anough:
例如
char buffer[512];
sprintf(buffer, "%s %s", front_name, backname);
我不知道有缓冲区。 –
在你的情况下,缓冲区将是m [index] .p.something – suspectus
啊我看到,在printf(缓冲区等)中显示的stackoverflow中没有示例。再次谢谢你。我正在考虑使用3次strcat。 –
假设result
有足够的空间,使用此:
sprintf(result, "%s %s", front_name, backname);
如果你是在Linux上,你可以看看'asprintf()';它会为您分配正确的空间量,并返回指向该空间的指针(当然,数据格式化)。 –