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. eclipse设置全局编码为UTF-8的方法

    1.windows->Preferences...打开"首选项"对话框,左侧导航树,导航到general->Workspace,右侧Text file encoding ...

  2. Import Items – Validation Multiple Languages Description

    ð  提交标准请求创建和更新物料,因语言环境与处理次序方式等因素,造成物料中英(更多语言)描述和长描述混乱刷新. 症状: >>> Submit Standard Open Inter ...

  3. RabbitMQ Hello World

    RabbitMQ Hello World rabbitmq operation: C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.2\sbin ...

  4. 项目中遇到的HQL查询问题

    问题描写叙述: 目的:想要查询出全部最新版本号的组件 说明:组件:版本号 =1:n关系 ,假设这个组件仅仅有一个版本号也要可以查出来. 项目中使用的是内存数据库,无法看到表结构,这里的样例仅仅用于模拟 ...

  5. java里int类型转byte类型

    今天在做书上的一个例子的时候, 要使用byte类型,首先我很直接的就写到了byte b = 0XAA, 结果报错, 说从int转换到byte可能会有损失. 我当时就很奇怪, 为什么会出现这种情况呢? ...

  6. 在webkit中如何避免触发layout(重排)

    很多web开发者都已经意识到,在脚本执行中,DOM操作的用时可能比js本身执行时间要长很多,其中潜在的消耗基本上是由于触发了layout(即重排reflow:由DOM树构建为Render渲染树的过程) ...

  7. javascript闭包的应用

    我印象中,javascript的闭包属于进阶的范畴,无非是用来在面试中装装逼而已.你看我身边的一个小伙子,有一天我装逼地问他什么是javascript的闭包,他居然连听都没听说过.但他做起前端的东西来 ...

  8. 2016/3/13 MySQL 增删查改 CRUD 用代码实现

    用代码实现数据库数据输入 T-SQL语句 查询语句分几块 ①创建表 create table Car (Code varchar(50) primary key, #primary key 主键 定义 ...

  9. PyTorch 高级实战教程:基于 BI-LSTM CRF 实现命名实体识别和中文分词

    前言:译者实测 PyTorch 代码非常简洁易懂,只需要将中文分词的数据集预处理成作者提到的格式,即可很快的就迁移了这个代码到中文分词中,相关的代码后续将会分享. 具体的数据格式,这种方式并不适合处理 ...

  10. 设计模式-(17)策略模式 (swift版)

    一,概念: 策略模式定义了一系列的算法,并将每一个算法封装起来,而且使他们可以相互替换,让算法独立于使用它的客户而独立变化. 二,使用场景 1.针对同一类型问题的多种处理方式,仅仅是具体行为有差别时: ...