【发布时间】:2016-11-08 20:21:09
【问题描述】:
假设我有以下字符串和一个布尔值:
bool numberGiven = false
"@give chocolate"
"@give white chocolate"
"@give dark chocolate"
"@give white chocolate 10"
"@give dark chocolate 2"
我想使用 sscanf 将单词一起保存在 char[] 中,并将整数分别保存为 int。
我希望该数字是可选输入。用户不必输入数字,但如果输入,布尔值“numberGiven”将变为“true”。
我需要一个 if 语句来决定是否必须将 numberGiven 设为“true”。请注意,“项目名称”可以不仅仅是两个单词。例如,可以用 Kinder Schokolade Dark Chocolate 代替黑巧克力(当然最后是可选的整数)
【问题讨论】:
标签: c input command optional scanf