sprintf
用于组包,将零散的数据,按照固定的格式,组成字符串。一般用来发送信息
头文件:#include<stdio.h>
int sprintf(char *str, const char *format, ......)
返回值为实际组包的长度
sscanf
用于解包,解析特定格式的数据
头文件:#include<stdio.h>
int sscanf(const char *restrict str, const char *restrict format, ...)
%d 用于提取数值 '0' - '9'
%s 用于提取字符串,遇到 '\0' 、空格、回车就结束
%*d 跳过整数,%*s跳过字符串
%[width]s ,%[width]d 读取指定宽度的数据
%[a-z] 表示匹配 a 到 z 中任意字符(尽可能多的匹配)
%[aBc] 表示匹配a、B、c中任意一个
%[^aBc] 表示匹配非a、B、c的任意字符
标签:sscanf,匹配,int,char,字符串,格式化,const From: https://www.cnblogs.com/yachifeng/p/17202419.html