当前位置:网站首页>[C语言] sscanf如何实现sscanf_s?
[C语言] sscanf如何实现sscanf_s?
2022-08-11 07:39:00 【jianqiang.xue】
在MCU中并不支持sscanf_s,所以我们只能通过sscanf实现。
char user[33] = {
0};
char pass[33] = {
0};
sscanf_s(buf, "%s %s", user, pass);
// 用 sscanf实现
sscanf(buf, "%32[^ ] %32[^ ]", user, pass);

C 库函数 int sscanf(const char *str, const char *format, …) 从字符串读取格式化输入。
声明
下面是 sscanf() 函数的声明。
int sscanf(const char *str, const char format, …)
参数
str – 这是 C 字符串,是函数检索数据的源。
format – 这是 C 字符串,包含了以下各项中的一个或多个:空格字符、非空格字符 和 format 说明符。
format 说明符形式为 [=%[][width][modifiers]type=],具体讲解如下:
参数 描述
- 这是一个可选的星号,表示数据是从流 stream 中读取的,但是可以被忽视,即它不存储在对应的参数中。
width 这指定了在当前读取操作中读取的最大字符数。
modifiers 为对应的附加参数所指向的数据指定一个不同于整型(针对 d、i 和 n)、无符号整型(针对 o、u 和 x)或浮点型(针对 e、f 和 g)的大小: h :短整型(针对 d、i 和 n),或无符号短整型(针对 o、u 和 x) l :长整型(针对 d、i 和 n),或无符号长整型(针对 o、u 和 x),或双精度型(针对 e、f 和 g) L :长双精度型(针对 e、f 和 g)
type 一个字符,指定了要被读取的数据类型以及数据读取方式。具体参见下一个表格。
边栏推荐
猜你喜欢

TF通过feature与label生成(特征,标签)集合,tf.data.Dataset.from_tensor_slices

Redis source code: how to view the Redis source code, the order of viewing the Redis source code, the sequence of the source code from the external data structure of Redis to the internal data structu

The softmax function is used in TF;

2022 China Soft Drink Market Insights
1.2 - error sources

1106 2019数列 (15 分)

JUC并发编程

Pico neo3 Unity Packaging Settings

1046 punches (15 points)

查询跟踪快递单号物流,智能分析物流中转有延误的单号
随机推荐
无服务器+域名也能搭建个人博客?真的,而且很快
我的创作纪念日丨感恩这365天来有你相伴,不忘初心,各自精彩
【43. 字符串相乘】
TF中的四则运算
Two state forms of Service
1051 Multiplication of Complex Numbers (15 points)
基于微信小程序的租房小程序
Four startup modes of Activity
Activity的四种状态
6月各手机银行活跃用户较快增长,创半年新高
经典论文-MobileNet V1论文及实践
【LeetCode】链表题解汇总
2022-08-10 mysql/stonedb-慢SQL-Q16-耗时追踪
软件测试常用工具的用途及优缺点比较(详细)
2021-08-11 For loop combined with multi-threaded asynchronous query and collect results
1071 Small Gamble (15 points)
TF generates (feature, label) set through feature and label, tf.data.Dataset.from_tensor_slices
Unity开发者必备的C#脚本技巧
Mysql JSON对象和JSON数组查询
CIKM 2022 AnalytiCup Competition: 联邦异质任务学习