V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
lcj2class
V2EX  ›  C

在 C 中,如何正确拷贝字符串

  •  
  •   lcj2class · Dec 3, 2023 · 2932 views
    This topic created in 879 days ago, the information mentioned may be changed or developed.
    - https://liujiacai.net/blog/2023/12/02/strcpy/

    这两天稍微总结了下 strcpy 的问题,欢迎大家批评指正。
    7 replies    2023-12-06 19:44:37 +08:00
    PTLin
        1
    PTLin  
       Dec 3, 2023
    不错的文章,字符串真是没有银弹,哨兵,定长,单独记录长度,每个都在自己的场景下发光发热。
    anytk
        2
    anytk  
       Dec 3, 2023
    最佳实践不是 snprintf 来拷贝吗?同时考虑可移植性和安全性的话。
    adoal
        3
    adoal  
       Dec 3, 2023
    如果考虑 locale safety 就更复杂了
    ethusdt
        4
    ethusdt  
       Dec 3, 2023
    strdup
    yolee599
        5
    yolee599  
       Dec 3, 2023 via Android
    看了文章,在我的认知里只有以 \0 结尾的才叫字符串,所以我编程的时候都会做处理,从来没遇到过结尾不为 \0 导致的 Bug
    CodeTracker
        6
    CodeTracker  
       Dec 3, 2023
    先关注博客向前辈学习了
    lcj2class
        7
    lcj2class  
    OP
       Dec 6, 2023
    @PTLin #1 是的,看了下项目,处理方式也是百花齐放。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1455 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 16:43 · PVG 00:43 · LAX 09:43 · JFK 12:43
    ♥ Do have faith in what you're doing.