zoukankan      html  css  js  c++  java
  • Linux snprintf使用总结

    snprintf()函数用于将格式化的数据写入字符串,其原型为:
        int snprintf(char *str, int n, char * format [, argument, ...]);

    【参数】str为要写入的字符串;n为要写入的字符的最大数目,超过n会被截断;format为格式化字符串,与printf()函数相同;argument为变量。

    【返回值】成功则返回参数str 字符串长度,失败则返回-1,错误原因存于errno 中。

    snprintf()拷贝n-1个字符串到str中,同时在结尾添加'';所以若要拷贝的字符串长度为10,则n应该为11,如

    char buf[1024] = {0};

    char* tmp = "aaaaaaaaaaaaaaaaaa";

    snprintf(buf, strlen(tmp)+1, "%s", tmp);

    一天一天的满足,即一天一天的堕落!
  • 相关阅读:
    生成器和推导式
    闭包
    python
    python初识函数二
    python函数初识
    python文件操作二
    文件操作
    python集合,深浅copy
    Python安装、配置图文详解
    jsDoc 使用及配置!
  • 原文地址:https://www.cnblogs.com/wangliangblog/p/7091075.html
Copyright © 2011-2022 走看看