C语言 sscanf
#include <stdio.h> int sscanf(const char *str, const char *format, ...);
功能:从str指定的字符串读取数据,并根据参数format字符串来转换并格式化数据。
参数:
- str:指定的字符串首地址
- format:字符串格式,用法和scanf()一样
返回值:
- 成功:参数数目,成功转换的值的个数
- 失败: - 1
案例

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
int main(void)
{
char ch[] = "1+2=3";
int a, b, c;
// 将ch中的字符格式,转换为int格式 读取
sscanf(ch, "%d+%d=%d",&a,&b,&c);
printf("%d\n", a);
printf("%d\n", b);
printf("%d\n", c);
return 0;
}
来源:https://www.cnblogs.com/xiangsikai/p/12378550.html
