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);

    一天一天的满足,即一天一天的堕落!
  • 相关阅读:
    csp-s模拟103
    csp-s模拟102
    csp-s模拟101
    csp-s模拟100
    csp-s模拟99
    csp-s模拟98
    csp-s模拟97
    csp-s模拟96
    csp-s模拟95
    csp-s模拟94
  • 原文地址:https://www.cnblogs.com/wangliangblog/p/7091075.html
Copyright © 2011-2022 走看看