Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你好我试图在两个字符串之间添加一个空格并将它们复制到一个变量中
在 php 中,我们可以用 + 来添加它们
front_name = "hello"; back_name = "world"; full_name = strcpy(m[index].p.something, front_name + " " + backname); // should output hello world
在c中等效或正确的方法是什么?
如果将字符串复制到的缓冲区足够大,则 sprintf 将是理想的:
例如
char buffer[512]; sprintf(buffer, "%s %s", front_name, backname);
假设result有足够的空间,请使用:
result
sprintf(result, "%s %s", front_name, backname);