zoukankan      html  css  js  c++  java
  • snprintf函数说明

    int snprintf(char *restrict buf, size_t n, const char * restrict   format, ...);

    函数说明:最多从源串中拷贝 n 1 个字符到目标串中,然后再在后面加一个 0 。所以如果目标串的大小为 n

                     的话,将不会溢出。

    函数返回值:若成功则返回欲写入的字符串长度,若出错则返回负值。

    Result1( 推荐的用法 )


     

    root] /root/lindatest
    $ ./test
    str=012345678

     

     

    Result2:(不推荐使用)


     

    root] /root/lindatest
    $ ./test
    str=01234567890123456

     

     

    snprintf函数返回值的测试:


    [root] /root/lindatest
    $ ./test
    aaabbbccc length=9
    str1=abc,ret1=3
    str2=aaa,ret2=9

  • 相关阅读:
    课程评价
    6.1-6.7 第十六周总结
    5.31 软件开发日志
    5.25-5.31 第十五周总结
    5.30 软件开发日志
    5.29 软件开发日志
    5.28 软件开发日志
    对搜狗输入法的评价
    找水王
    用户模板/用户场景
  • 原文地址:https://www.cnblogs.com/hjslovewcl/p/2314360.html
Copyright © 2011-2022 走看看