TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Preferred string copy function in C?

1 点作者 codehero大约 13 年前
1. strcpy<p>2. strncpy<p>3. stpcpy<p>4. memcpy

3 条评论

cd34大约 13 年前
Depending on your requirements, each has its benefits and drawbacks. Depending on your architecture, there are versions that are faster than the libc version.<p>None of the functions you have listed are true equivalents, so, your situation will dictate which you need to use.
评论 #3912538 未加载
steve-howard大约 13 年前
strdup is nice, but it always depends on your use case.<p>memcpy is probably best if you're keeping track of lengths separately.
tlb大约 13 年前
strlcpy