sprintf使用

使用sprintf把数字转换成字符串是个好方法,不过需要注意sprintf会自动在字符串末尾加结束符,所以字符串的长度需要比要转换的数字位数多1.

char string[6];

sprintf(string,"%5d",1);

这样string变成“00001”,确实很方便。

原文地址:https://www.cnblogs.com/zcdqs/p/2622548.html