sscanf函数是C语言中的输入函数,用于从字符串中格式化读取数据。
其基本的语法格式是: int sscanf(const char *str, const char *format, …);
参数说明:
返回值:
示例:
#include <stdio.h>
int main() {
char str[] = "Tom 25";
char name[10];
int age;
sscanf(str, "%s %d", name, &age);
printf("Name: %s\n", name);
printf("Age: %d\n", age);
return 0;
}
输出结果:
Name: Tom
Age: 25
在上述示例中,sscanf函数从字符串str中按照指定的格式"%s %d"读取数据,将名字赋值给name变量,年龄赋值给age变量,并通过printf函数打印出来。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:c语言sscanf函数的用法是什么