临时1

#include <stdio.h> // void perror(const char *msg);

#include <string.h> // char *strerror(int errnum);
#include <errno.h> //errno

errno 是错误代码,在 errno.h头文件中;

perror是错误输出函数,输出格式为:msg:errno对应的错误信息(加上一个换行符);

strerror 是通过参数 errnum (就是errno),返回对应的错误信息。

 

int snprintf(char *str, size_t size, const char *format, ...);

ret = snprintf();

成功 ret = 预写入的字符串长度(不包括'/0'),失败, ret = 负值。

The functions snprintf() and vsnprintf() do not write more than size bytes (including the trailing '/0').

 

#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
 char str1[10]={0,},str2[10]={0,};
 int ret1,ret2;
 char *mac="abc";

 ret1 = snprintf(str1,3,"%s","abc");
 ret2 = snprintf(str2,50,"%s","aaabbbcccddd");

 printf("ret1= %d, str1= %s/n",ret1,str1);
 printf("ret2= %d, str2= %s/n",ret2,str2);
 printf("%d/n",sizeof("abc"));
 printf("%d/n",strlen("abc"));
}

 

/********************/

[andrew@localhost new]$ ./test
ret1= 3, str1= ab
ret2= 12, str2= aaabbbcccddd
4
3

/****************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值