连接两个字符数组? [英] Concatenate two char arrays?
本文介绍了连接两个字符数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有两个字符数组,像这样:
If I have two char arrays like so:
char one[200];
char two[200];
然后我想使其中三分之一连接这些我怎么能这样做呢?
And I then want to make a third which concatenates these how could I do it?
我曾尝试:
char three[400];
strcpy(three, one);
strcat(three, two);
不过,这似乎并没有工作。确实,如果有一个
和两个
设置是这样的:
char *one = "data";
char *two = "more data";
任何人有任何想法如何解决这一问题?
Anyone got any idea how to fix this?
感谢
推荐答案
如果'一'和'二'不包含'\\ 0'结尾的字符串,那么你可以使用这样的:
If 'one' and 'two' does not contain a '\0' terminated string, then you can use this:
memcpy(tree, one, 200);
memcpy(&tree[200], two, 200);
这将复制所有的字符来自一个和两个字符串,不考虑终止符'\\ 0'
This will copy all chars from both one and two disregarding string terminating char '\0'
这篇关于连接两个字符数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文