当前位置:网站首页>[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 一个字符,指定了要被读取的数据类型以及数据读取方式。具体参见下一个表格。
边栏推荐
- 如何仅更改 QGroupBox 标题的字体?
- leetcode: 69. Square root of x
- Unity开发者必备的C#脚本技巧
- Distributed Lock-Redission - Cache Consistency Solution
- 1061 判断题 (15 分)
- 囍楽cloud task source code
- 1002 Write the number (20 points)
- oracle19c does not support real-time synchronization parameters, do you guys have any good solutions?
- 1051 Multiplication of Complex Numbers (15 points)
- 选择收银系统主要看哪些方面?
猜你喜欢
随机推荐
excel 透视表 值显示内容 不显示计数
1051 Multiplication of Complex Numbers (15 points)
Service的两种启动方式与区别
The most complete documentation on Excel's implementation of grouped summation
8、Mip-NeRF
Use tf.argmax in Tensorflow to return the index of the maximum value of the tensor along the specified dimension
One-hot in TF
redis操作
1096 大美数 (15 分)
如何仅更改 QGroupBox 标题的字体?
Conditional statements in TF; where()
3.2-分类-Logistic回归
matrix multiplication in tf
[Recommender System]: Overview of Collaborative Filtering and Content-Based Filtering
3.1-分类-概率生成模型
redis operation
项目2-年收入判断
3.1-Classification-probabilistic generative model
Activity的四种启动模式
【C语言】每日一题,求水仙花数,求变种水仙花数