问题描述
将Char *复制到Char *的最佳方法是什么?
What is the best way to copy a Char* to a Char*?
推荐答案
这取决于你的意思。 />
没有标准类型Char;我认为你的意思是char。
要将char *对象的值复制到另一个,只需指定它。
复制一个字符串,使用strcpy()(但首先要确保目标
有足够的空间)。
如果要复制的字符数组不是'字符串,使用memcpy()
(如果它们可能重叠,则为memmove())。
-
Keith汤普森(The_Other_Keith)< http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
That depends on what you mean.
There is no standard type Char; I presume you mean char.
To copy the value of a char* object to another one, just assign it.
To copy a string, use strcpy() (but first make sure that the target
has enough room).
If you''re copying character arrays that aren''t strings, use memcpy()
(or memmove() if they might overlap).
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
int main(void)
{
typedef char Char;
Char * a = 0;
Char * b = 0;
a = b;
返回0;
}
我已经给出了你的问题的字面答案。
我怀疑你需要更具体地说一下
来得到你真正需要的答案。
-Mike
int main(void)
{
typedef char Char;
Char *a = 0;
Char *b = 0;
a = b;
return 0;
}
I''ve given a literal answer to your question.
I suspect you''ll need to phrase it more specifically
to get the answer you really need.
-Mike
C中没有''Char''我猜你在谈论''char''。
使用''=''运算符。
char * pa =" hello";
char pb;
pb = pa;
如果你的意思'C-string'',请更具体。
-
A +
Emmanuel Delahaye
No ''Char'' in C. I guess you are talking about ''char''.
Use the ''='' operator.
char *pa = "hello";
char pb;
pb = pa;
If you meant ''C-string'', please, be more specific.
--
A+
Emmanuel Delahaye
这篇关于Char * to Char *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!