给定开始和结束索引,如何在 C 中复制部分字符串? [英] Given a starting and ending indices, how can I copy part of a string in C?

查看:18
本文介绍了给定开始和结束索引,如何在 C 中复制部分字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C 中,如何复制带有开始和结束索引的字符串,以便只复制部分字符串(从开始索引到结束索引)?

In C, how can I copy a string with begin and end indices, 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 ( char * destination, const char * source, size_t num );

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

您必须意识到beginend 实际上定义了要从一个地方复制到另一个地方的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天全站免登陆