sprintf函数的用法
说明1:该函数包含在stdio.h的头文件中,使用时需要加入:#include <stdio.h>
除了前两个参数固定外,可选参数可以是任意个。buffer是字符数组名;format是格式
化字符串(像:"=%6.2f%#x%o",%与#合用时,自动在十六进制数前面加上0x)。只要在printf中可以使用的格式化字符串,在
sprintf都可以使用。其中的格式化字符串是此函数的精华。
double f=14.309948;
sprintf(str,"%6.2f",f);
说明5:可以将多个数值数据连接起来。
sprintf(str,"=m",a,b);
str[]="20984 48090"
说明6:可以将多个字符串连接成字符串
char s1={'A','B','C'};
char s2={'T','Y','x'};
sprintf(str,"%.3s%.3s",s1,s2);
说明7:可以动态指定,需要截取的字符数
char s2={'T','Y','x'};
sprintf(str,"%.*s%.*s",2,s1,3,s2);
sprintf(s, "%*.*f", 10, 2, 3.1415926);
说明8:可以打印出i的地址:sprintf(s, "%p", &i);相当于sprintf(s, "%0*x", 2 * sizeof(void *), &i);
sprintf函数的用法的更多相关文章
- C语言中sprintf()函数的用法
sprintf函数的用法 1.该函数包含在stdio.h的头文件中. 2.sprintf和平时我们常用的printf函数的功能很相似.sprintf函数打印到字符串中,而printf函数打印输出到屏幕 ...
- sprintf()函数的用法
Visual C++ sprintf()函数用法 转:http://blog.csdn.net/masikkk/article/details/5634886 在将各种类型的数据构造成字符串时,spr ...
- php sprintf 函数的用法
sprintf() 函数把格式化的字符串写入变量中. arg1.arg2.++ 参数将被插入到主字符串中的百分号(%)符号处.该函数是逐步执行的.在第一个 % 符号处,插入 arg1,在第二个 % 符 ...
- perl中sprintf函数的用法
对于某些字符串,需要输入为特定的格式,通过sprintf可以很方便的完成,不需要专门进行其他处理. 转载 perl中sprintf函数的使用方法.
- sprintf()函数基本用法
基本用法 sprintf 是个变参函数,定义如下: int sprintf( char *buffer, const char *format [, argument] ... ); sprintf的 ...
- sprintf()函数的用法
sprintf(g_strAppName, "%s",pLast+1); ----------------------------------------------------- ...
- 转:Visual C++ sprintf()函数用法
将字串格式化命令.sprintf 是个变参函数,使用时经常出问题,而且只要出问题通常就是能导致程序崩溃的内存访 问错误,但好在由sprintf 误用导致的问题虽然严重,却很容易找出,无非就是那么几种情 ...
- sprintf,snprintf的用法(可以作为linux中itoa函数的补充)【转】
转自:http://blog.csdn.net/educast/article/details/25068445 函数功能:把格式化的数据写入某个字符串 头文件:stdio.h 函数原型:int sp ...
- sprintf函数
sprintf函数用法举例 #include<stdio.h> int main() { //1.连接字符串 char a1[] = {'A', 'B', 'C', 'D', 'E', ' ...
随机推荐
- oracle中获取执行计划
1. 预估执行计划 - Explain PlanExplain plan以SQL语句作为输入,得到这条SQL语句的执行计划,并将执行计划输出存储到计划表中. 首先,在你要执行的SQL语句前加expla ...
- sql 链接符 ||
- Python3 抓取豆瓣电影Top250
利用 requests 抓取豆瓣电影 Top 250: import re import requests def main(url): global num headers = {"Use ...
- iPhone较为基础的代码片段
Iphone代码片段导航 1.给UITableViewController添加ToolBar. self.navigationController.toolbarHidden = NO; //默认是隐 ...
- 使用WdatePicker获取比当前时间大的写法
<input name="today.date" class="Wdate" type="text" onClick="Wd ...
- 【Redis】 make编译是提示 make cc Command not found
在linux系统上对redis源码进行编译时提示提示“make cc Command not found,make: *** [adlist.o] Error 127”. 这是由于系统没有安装gcc环 ...
- JS-键盘事件之方向键移动元素
注意三点: 1:事件名称onkeydown. 2:事件加给document,而非window. 3: 把元素的top,left值分别用offsetTop,offsetLeft来设定. <!DOC ...
- Android长截屏-- ScrollView,ListView及RecyclerView截屏
http://blog.csdn.net/wbwjx/article/details/46674157 Android长截屏-- ScrollView,ListView及RecyclerV ...
- hdu5009 Paint Pearls[指针优化dp]
Paint Pearls Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- CHECKSUM比较两表字段值差异
CHECKSUM 返回在表的行上或在表达式列表上计算的校验值.CHECKSUM 用于生成哈希索引. 语法 CHECKSUM ( * | expression [ ,...n ] ) 参数 * 指定在表 ...