[英]How to read string until two consecutive spaces?
scanf()
函數的一個眾所周知的功能是您可以根據此格式傳遞格式以掃描輸入。
我有一個字符串( sInput
)如下:
#something VAR1 this is a constant string //some comment
其中VAR1
是常量字符串的名稱, this is a constant
。
現在我正在掃描這個字符串,如下所示:
if(sscanf(sInput, "%*s %s %s", paramname, constantvalue) != 2)
//do something
當然,當我輸出paramname
和constantvalue
我得到:
VAR1
this
但我希望有constantvalue
來包含字符串,直到找到兩個連續的空格(因此它將包含該部分, this is a constant string
)。
所以我試過:
sscanf(sInput, "%*s %s %[^( )]s", paramname, constantvalue)
sscanf(sInput, "%*s %s %[^ ]s", paramname, constantvalue)
但沒有運氣。 有沒有辦法用sscanf()
實現我的目標? 或者我應該實現另一種存儲字符串的方法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.