C语言 - 获得几句话之间的逗号 [英] language c - get few words with comma between
问题描述
我想知道它是如何可能做到这一点:
I would like to know how it's possible to do this :
其实我只是做了一些基本的程序,并且用户(通过当然是scanf函数)进入这样的:
I am actually doing some basic program, and the user has to enter something like this (via a scanf of course) :
字词1,word2和WORD3
word1,word2,word3
但我想获得的在一个变量每一个字,这意味着没有 。 (但是,用户必须输入)。
BUT I would like to get each word in one variable, that means without ,. (But the user has to enter the ,).
所以我想:$字词1,$字词2,...
So I want to get : $word1, $word2, ...
-
这怎么可能?
我不能使用循环或C的复杂功能(它是由运动禁止的)。它必须是非常基本的
I can't use loop or complex functions of c (it's forbidden by the exercise). It has to be very basic.
感谢通过提前帮助..;)
Thanks by advance for help.. ;)
推荐答案
如果总是会有只有三个字输入,那么是可以最肯定使用的 scanf函数
,因为它实际上简单的模式匹配:
If there will always be only three words in the input, then yes can most definitely use scanf
, because it actually does simple pattern matching:
if (scanf("%[^ ,] , %[^ ,] , %[^ \n]", string1, string2, string3) == 3)
{
/* Read three words */
}
如果你可以有一个可变数目的话,那么阅读的 strtok的
。
If you can have a variable number of words, then read about strtok
.
这篇关于C语言 - 获得几句话之间的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!