c等同于“复制” [英] c equivilant to "copy"
问题描述
问候,
我一直试图找到c ++复制功能的等效功能。
描述:
copy(char * cstring,size_t count,size_t offset);
复制count从偏移量开始的C风格字符串中的字符。
假设我有字符串Hello There我只需要llo部分
来自你好的
。我怎么做到这一点?使用c ++我可以使用
复制功能。
任何帮助都将不胜感激,
谢谢!
Greetings,
I''ve been trying to find an equivant c funtion to the c++ copy function.
Description:
copy(char *cstring, size_t count, size_t offset);
Copies "count" characters from a C-style string starting at offset.
Let''s say I have the string "Hello There" and I needed only the "llo" part
from hello. How would I accomplish this? Using the c++ I could use the
copy function.
Any help would be appreciated,
Thanks!
推荐答案
Shagy写道:
Shagy wrote:
问候,
我一直试图找到一个等效的功能复制功能。
复制(char * cstring,size_t count,size_t offset);
复制计数从偏移量开始的C风格字符串中的字符。
假设我有字符串Hello There我只需要llo部分来自你好。我怎么做到这一点?使用c ++我可以使用
复制功能。
任何帮助将不胜感激,
谢谢!
Greetings,
I''ve been trying to find an equivant c funtion to the c++ copy function.
Description:
copy(char *cstring, size_t count, size_t offset);
Copies "count" characters from a C-style string starting at offset.
Let''s say I have the string "Hello There" and I needed only the "llo" part
from hello. How would I accomplish this? Using the c++ I could use the
copy function.
Any help would be appreciated,
Thanks!
可能你在问什么...
strncpy(dest,cstring + offset,count);
dest [count] =''\'0' ';
假设dest大到足以保持''count + 1''字符。
Krishanu
>
Krishanu Debnath写道:
Krishanu Debnath wrote:
Shagy写道:
Shagy wrote:
问候,
我'一直试图找到一个相当的功能来实现c ++复制功能。
描述:
复制(char * cstring,size_t count,size_t offset );
副本计数来自偏移的C风格字符串中的字符。
假设我有字符串Hello There
而我只需要llo字符串。来自你好。
如何实现这个目标?
使用c ++我可以使用复制功能。
Greetings,
I''ve been trying to find an equivant c funtion to
the c++ copy function.
Description:
copy(char *cstring, size_t count, size_t offset);
Copies "count" characters from a C-style string starting at offset.
Let''s say I have the string "Hello There"
and I needed only the "llo" part from hello.
How would I accomplish this?
Using the c++ I could use the copy function.
可能你问的是什么...
strncpy(dest,cstring + offset,count);
dest [count] =''\ 0'';
假设dest大到足以保持''count + 1 ''character。
Probably what you are asking ...
strncpy(dest, cstring + offset, count);
dest[count] = ''\0'';
assuming dest in large enough to hold ''count + 1'' character.
由于你没有复制整个字符串,
memcpy和strncpy一样好。
/ * BEGIN new.c * /
#include< string.h>
#include< stdio。 h>
int main(无效)
{
char dest [sizeof" llo"];
size_t count;
count = sizeof dest - 1;
memcpy(dest,Hello There+ 2,count);
dest [count] =''\''';
puts(dest);
返回0;
}
/ * END new.c * /
Since you are not copying an entire string,
memcpy would work just as well as strncpy.
/* BEGIN new.c */
#include <string.h>
#include <stdio.h>
int main(void)
{
char dest[sizeof "llo"];
size_t count;
count = sizeof dest - 1;
memcpy(dest, "Hello There" + 2, count);
dest[count] = ''\0'';
puts(dest);
return 0;
}
/* END new.c */
谢谢!!!
Bot h示例工作得很好!!!
Shagy
" Shagy" <无***** @ noemail.com>在消息中写道
news:cs ********** @ nic.grnet.gr ...
Thanks!!!
Both examples work great!!!
Shagy
"Shagy" <no*****@noemail.com> wrote in message
news:cs**********@nic.grnet.gr...
问候,
我是我一直试图找到c ++复制功能的等效功能。
描述:
复制(char * cstring,size_t count,size_t offset);
副本计数从偏移量开始的C风格字符串中的字符。
假设我有字符串Hello There我只需要你好的llo
部分。我怎么做到这一点?使用c ++我可以使用
复制功能。
任何帮助将不胜感激,
谢谢!
Greetings,
I''ve been trying to find an equivant c funtion to the c++ copy function.
Description:
copy(char *cstring, size_t count, size_t offset);
Copies "count" characters from a C-style string starting at offset.
Let''s say I have the string "Hello There" and I needed only the "llo"
part from hello. How would I accomplish this? Using the c++ I could use
the copy function.
Any help would be appreciated,
Thanks!
这篇关于c等同于“复制”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!