C中的可变参数scanf [英] variadic scanf in C

查看:237
本文介绍了C中的可变参数scanf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇能否在C语言中实现scanf的可变版本.我的意思是,如果输入为push (1 2 3),则scanf可以将其解析为%s %d %d %d就像scanf("%s (%d)", string, some_list).

I was curious if it's possible to implement a sort of variadic version of scanf in C. What I mean is if the input is push (1 2 3), scanf would be able to parse that into %s %d %d %d with something like scanf("%s (%d)", string, some_list).

它将使用%d的所有实例并将它们(按顺序)附加到列表中...

It would take all instances of %d and append them (in order) to the list...

我在说话吗?

对于指定的输入,string == "push"some_list == [1, 2, 3].

推荐答案

不是 vscanf,vssscanf,vsfcanf 是您要找的东西吗?从C99开始可以使用它们.

Isn't vscanf, vssscanf, vsfcanf is what you are looking for? They are avaialble from C99 onwards.

以下是

Here is a decription and example of usage of vscanf function. Note that C being a compiled and a strongly typed language, you need to give format specifiers properly. Doing something like what higher languages dos is going to involve more work (but is possible because features are inturn written in C).

这篇关于C中的可变参数scanf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆