sprintf() 数字转字符串
sscanf() 字符串转数字
测试代码:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char *p1="port: 5060";
unsigned short us;
sscanf(p1,"port: %hd", &us);
printf("%hd\n", us);
char p2[64] = {'x'};
sprintf(p2,"port: %d", us+1);
printf("%s\n", p2);
return 0;
}
另:
printf() 与 scanf() 中的 字符串格式
%[flags][width][.prec][F|N|h|l]type
flags
字符
|
字符名称 | 说明 |
- | 减号 | 左对齐,右边填充空格(默认右对齐) |
+
|