如何读取使用scanf的空间分隔的数字 [英] How to read numbers separated by space using scanf

查看:342
本文介绍了如何读取使用scanf的空间分隔的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的使用scanf()的函数用空格分隔的数字(整型)。结果
我已阅读以下

I want to read numbers(integer type) separated by spaces using scanf() function.
I have read the following

<一个href=\"http://stackoverflow.com/questions/2539796/c-reading-multiple-numbers-from-single-input-line-scanf\">C,从单一的输入线读取多个号码(scanf函数?)
结果
如何阅读用空格结果scanf函数
它并不能帮助我很多。
我怎样才能读取空间分隔符的数字。对于如我有以下电话号码输入 2 5 7 4 3 8 18 现在我想将这些存储在不同的变量。请帮忙。

C, reading multiple numbers from single input line (scanf?)
how to read scanf with spaces
It doesn't help me much. How can I read numbers with space as delimiter. For e.g. I have following numbers as input 2 5 7 4 3 8 18 now I want to store these in different variables.
Please help.

推荐答案

我觉得由scanf函数与空间读取默认值/进入。那么你可以,如果你要打印整数提供'%D'之间的空间。也同样为其他案件。

I think by default values read by scanf with space/enter. Well you can provide space between '%d' if you are printing integers. Also same for other cases.

scanf("%d %d %d", &var1, &var2, &var3);

同样的,如果你想读逗号分隔值是:

Similarly if you want to read comma separated values use :

scanf("%d,%d,%d", &var1, &var2, &var3);

这篇关于如何读取使用scanf的空间分隔的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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