snprintf函数用法
来源:互联网 发布:mac下制作win7安装u盘 编辑:程序博客网 时间:2024/06/05 02:06
int snprintf(char *restrict buf, size_t n, const char * restrict format, ...);
函数说明:最多从源串中拷贝n-1个字符到目标串中,然后再在后面加一个0。所以如果目标串的大小为n 的话,将不会溢出。
函数返回值:若成功则返回欲写入的字符串长度,若出错则返回负值。
#include <stdio.h>
#include <stdlib.h>
int main()
{
char str[10]={0};
snprintf(str, sizeof(str), "0123456789101112");
printf("str=%s/n", str);
return 0;
}
运行结果为:
str=012345678
char test[8];
int ret = snprintf(test,5,"1234567890");
printf("ret=%d,test=%s/n",ret,test);
运行结果为:
ret=10,test=1234
int pid =getpid();
snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid )
0 0
- snprintf函数用法
- snprintf函数用法
- snprintf函数的用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数的用法
- snprintf函数用法
- 【转】snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法
- snprintf函数用法 .
- HDU 3452 Bonsai(网络流之最小割)
- poj1149PIGS(最大流+建图)
- 为什么程序员的工作效率跟他们的工资不成比例
- 客户端怎么判断Socket连接已与服务器断开
- Swift与OC混编
- snprintf函数用法
- 2014年 嵌入式Linux会议LinuxCon欧洲的时间表公布
- Hibernate 插入数据库时 线程挂起,有点像死循环
- 你还在问android横竖屏切换的生命周期?
- Jep java表达式分析器
- 在线正则表达式
- 新建AVD找不到路径的解决办法
- 【源码】LinkedHashMap源码剖析
- 严苛模式(StrictMode)