sprintf

int sprintf ( char * str, const char * format, ... );
Write formatted data to string

Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in
the buffer pointed by str.

The size of the buffer should be large enough to contain the entire resulting string (see snprintf for a safer version).

A terminating null character is automatically appended after the content.

After the format parameter, the function expects at least as many additional arguments as needed for format.

Parameters

str
Pointer to a buffer where the resulting C-string is stored.

The buffer should be large enough to contain the resulting string.
format
C string that contains a format string that follows the same specifications as format in printf (see printf for
details).
... (additional arguments)
Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage
location, for n).

There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.

Return Value

On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string.

On failure, a negative number is returned.

中文版:

函数功能:把格式化的数据写入某个字符串
函数原型:int sprintf( char *buffer, const char *format [, argument] … );
返回值:字符串长度(strlen)

例子:
char* who = "I";
char* whom = "CSDN";
sprintf(s, "%s love %s.", who, whom); //产生:"I love CSDN. " 这字符串写到s中

sprintf(s, "%10.3f", 3.1415626); //产生:" 3.142"

C plus plus sprintf用法的更多相关文章

  1. C++小知识之sprintf用法

    sprintf   字串格式化命令,主要功能是把格式化的数据写入某个字符串中.sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内存访问错误,但好在由sprintf ...

  2. sprintf 用法

    字符串格式化命令,主要功能是把格式化的数据写入某个字符串中 试试下面的代码就知道了 #include<cstdio> #include<cstdlib> using names ...

  3. php sprintf用法

    sprintf用来格式化字符串 说明 string sprintf ( string $format [, mixed $args [, mixed $... ]] 参数 $format 可能的格式值 ...

  4. sscanf,sprintf用法

    #include<string.h> #include<stdio.h> int main() { ],sztime1[],sztime2[]; sscanf("12 ...

  5. sprintf用法

    函数简介 函数功能:把格式化的数据写入某个字符串 头文件:stdio.h 函数原型:int sprintf( char *buffer, const char *format [, argument] ...

  6. c++ sprintf() 用法

    1. char  boxData[100]; fi.mWidth = 1.0, fi.mCenter_x= 2.1, fi.mCenter_y=1.1; sprintf(boxData, " ...

  7. WordPress翻译中 __()、_e()、_x、_ex 和 _n 的用法及区别

    编译函数 WordPress使用了下面几个函数来方便语言本地化. __() _e() _x() _ex() _n() 以上所列的函数是用来包含所需翻译的字符串的,根据字符串的不同参数和输出类型,需要使 ...

  8. sprintf()详细介绍

    sprintf 编辑词条 编辑词条 -->   字串格式化命令,主要功能是把格式化的数据写入某个字符串中.sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内 ...

  9. sprintf格式化字符串安全问题

    先看sprintf用法: 定义和用法 sprintf() 函数把格式化的字符串写入变量中. arg1.arg2.++ 参数将被插入到主字符串中的百分号(%)符号处.该函数是逐步执行的.在第一个 % 符 ...

随机推荐

  1. linux上安装启动elasticsearch-5.5.1完整步骤

    linux上安装启动elasticsearch-5.5.1完整步骤 学习了:https://blog.csdn.net/hingcheung/article/details/77144574 http ...

  2. protobuf 之 MessageLite 接口摘录

    class LIBPROTOBUF_EXPORT MessageLite { public: inline MessageLite() {} virtual ~MessageLite(); // Ba ...

  3. 【iOS系列】-iOS的多线程解析

    [iOS系列]-iOS的多线程解析 iOS的多线程实现技术: 1:GCD -- Grand Central Dispatch 是基于C语言的底层API 用Block定义任务,使用起来非常灵活便捷 提供 ...

  4. IOS开发基础之—MD5加密算法【转】

    原文地址:http://blog.csdn.net/pjk1129/article/details/6855024 #import <CommonCrypto/CommonDigest.h> ...

  5. 从头认识java-15.1 填充容器(3)-填充Map

    这一章节我们来讨论一下填充容器的还有一个方面Map.之前的两个章节我们都是用list来作为容器.这一章节我们使用Map. 还有在这里解释一下为什么一直都使用生成器这个东西,事实上他就是建造者设计模式, ...

  6. /dev/zero和/dev/null的区别

    http://www.cnblogs.com/jacktu/archive/2010/06/28/1766791.html /dev/zero和/dev/null的区别   使用/dev/null 把 ...

  7. Oracle修改序列(Sequence)起始值问题

    Oracle 序列(Sequence)主要用于生成流水号,在应用中经常会用到,特别是作为ID值,拿来做表主键使用较多. 但是,有时需要修改序列初始值(START WITH)时,有同仁使用这个语句来修改 ...

  8. Linux如何查看进程等常用命令

    1.查进程    ps命令查找与进程相关的PID号:    ps a 显示现行终端机下的所有程序,包括其他用户的程序.    ps -A 显示所有程序.    ps c 列出程序时,显示每个程序真正的 ...

  9. Posting array of JSON objects to MVC3 action method via jQuery ajax

    Does the model binder not suport arrays of JSON objects? The code below works when sending a single ...

  10. XMU C语言程序设计实践(2)

    任务一:颠倒的世界 小明最近突然喜欢倒着写字,写出来的句子全是颠倒的,也就是把一句话里的字符全都逆序写,譬如“I Love This Game!”,他就偏偏要写成“!emaG sihT evoL I” ...