我怎样才能复制用C另一个字符串的一部分,给定一个起始和结束索引 [英] How can I copy part of another string in C, given a starting and ending index

查看:130
本文介绍了我怎样才能复制用C另一个字符串的一部分,给定一个起始和结束索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以复制一个字符串(C语言)有开始和结束指数,
使得弦将仅部分地复制(从开始索引结束索引)。

How can I copy a string (in C) with a begin and end index, so that the string will only be partially copied (from begin index to end index).

这就像'C字符串拷贝的strcpy ,但有开始和结束索引。

This would be like 'C string copy' strcpy, but with a begin and an end index.

推荐答案

你检查的函数strncpy

的char *函数strncpy(字符*目的地,为const char *源,为size_t NUM);

char * strncpy ( char * destination, const char * source, size_t num );

您必须认识到的开始的和的结束的真正定义了一个 NUM 字节从一个地方复制到另一个。

You must realize that begin and end actually defines a num of bytes to be copied from one place to another.

这篇关于我怎样才能复制用C另一个字符串的一部分,给定一个起始和结束索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆