当前位置:网站首页>[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 一个字符,指定了要被读取的数据类型以及数据读取方式。具体参见下一个表格。
边栏推荐
- 2021-08-11 For loop combined with multi-threaded asynchronous query and collect results
- oracle19c不支持实时同步参数,请教一下大佬们有什么好的解决办法吗?
- Four states of Activity
- 1051 Multiplication of Complex Numbers (15 points)
- 我的创作纪念日丨感恩这365天来有你相伴,不忘初心,各自精彩
- My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful
- 【TA-霜狼_may-《百人计划》】图形3.7.2 command buffer简
- 项目2-年收入判断
- Four startup modes of Activity
- Service的两种状态形式
猜你喜欢
随机推荐
抽象类和接口
囍楽云任务源码
tf.reduce_mean() and tf.reduce_sum()
通过记账,了解当月收支情况
break pad源码编译--参考大佬博客的总结
Test cases are hard?Just have a hand
The easiest trick to support quick renaming of various files
tf中自减操作;tf.assign_sub()
Find the latest staff salary and the last staff salary changes
1071 Small Gamble (15 points)
Four startup modes of Activity
3.2-分类-Logistic回归
求职简历这样写,轻松搞定面试官
2022年中国软饮料市场洞察
项目1-PM2.5预测
囍楽cloud task source code
tf.reduce_mean()与tf.reduce_sum()
klayout--导出版图为gds文件
测试用例很难?有手就行
My creative anniversary丨Thank you for being with you for these 365 days, not forgetting the original intention, and each is wonderful