博客
关于我
C语言之字符串探究(六):sprintf——把格式化的数据写入某个字符缓冲区
阅读量:224 次
发布时间:2019-02-28

本文共 700 字,大约阅读时间需要 2 分钟。

相关博文:

相关博文:
相关博文:
相关博文:
相关博文:
相关博文:
相关博文:
相关博文:
相关博文:
相关博文:
相关博文:
相关博文:

sprintf

  int sprintf(char ∗ \ast str,const char ∗ \ast format,…)

功能:
  根据参数format字符串来转换并格式化数据,然后将结果输出到str指定的空间中,直到出现字符串结束符’\0’为止。
功能:
  str:字符串首地址
  format:字符串格式,用法和printf()一样
返回值:
  成功:实际格式化的字符个数
  失败:-1

例1:

在这里插入图片描述
附例1代码:

//小问学编程#include
#include
int main(){ int a,b,c,d; printf("pls input ip:"); scanf("%d.%d.%d.%d",&a,&b,&c,&d); char buf[16]; sprintf(buf,"%d.%d.%d.%d",a,b,c,d); printf("%s\n",buf); return 0;}

例2:

在这里插入图片描述
附例2代码:

//小问学编程#include
#include
int main(){ char buf[1024]={ 0}; sprintf(buf,"Hello %s!","Obama"); printf("buf:%s\n",buf); return 0;}

转载地址:http://ashp.baihongyu.com/

你可能感兴趣的文章
Mysql 拼接多个字段作为查询条件查询方法
查看>>
mysql 排序id_mysql如何按特定id排序
查看>>
Mysql 提示:Communication link failure
查看>>
mysql 插入是否成功_PDO mysql:如何知道插入是否成功
查看>>
Mysql 数据库InnoDB存储引擎中主要组件的刷新清理条件:脏页、RedoLog重做日志、Insert Buffer或ChangeBuffer、Undo Log
查看>>
mysql 数据库中 count(*),count(1),count(列名)区别和效率问题
查看>>
mysql 数据库备份及ibdata1的瘦身
查看>>
MySQL 数据库备份种类以及常用备份工具汇总
查看>>
mysql 数据库存储引擎怎么选择?快来看看性能测试吧
查看>>
MySQL 数据库操作指南:学习如何使用 Python 进行增删改查操作
查看>>
MySQL 数据库的高可用性分析
查看>>
MySQL 数据库设计总结
查看>>
Mysql 数据库重置ID排序
查看>>
Mysql 数据类型一日期
查看>>
MySQL 数据类型和属性
查看>>
mysql 敲错命令 想取消怎么办?
查看>>
Mysql 整形列的字节与存储范围
查看>>
mysql 断电数据损坏,无法启动
查看>>
MySQL 日期时间类型的选择
查看>>
Mysql 时间操作(当天,昨天,7天,30天,半年,全年,季度)
查看>>