自定义字符串
sprintf字符串格式化命令
字符串声明:
int sprintf(char *string, char *format [,argument,…]);
1.整形固定位数输出
#defineMAX_MESSAGEID_SIZE15inttestNum=3;inttestNum=99;charcode[MAX_MESSAGEID_SIZE];charcode1[MAX_MESSAGEID_SIZE];sprintf(code,"%03d",testNum);sprintf(code1,"%03d",testNum);log_e("code[%s]code1[%s]);code输出结果
code[003] code1[099]2.多个字符串或整形连接
char*s="abcd";intnum=9;charcode[MAX_MESSAGEID_SIZE];sprintf(code,"%s%03d%d",s,num,num);log_e("code[%s]);code输出结果
code[abcd0099]