简体   繁体   English

在C / C ++ scanf()扫描集中指定']'字符

[英]Specifying the ']' character in a C/C++ scanf() scanset

I would like to use a scanf family function to extract a string delimited by ']'. 我想使用scanf家族函数提取以']'分隔的字符串。 For a delimiter of ')' one can do this: 对于')'的分隔符,可以这样做:

scanf(" %80[^)]", &buf); 

But how do you include the ']' in the scanset in general (not just the negated set case example above)? 但是,您通常如何在扫描集中包含“]”(不仅仅是上面的否定设置案例)? Is there some kind of escape seq for that? 为此是否有某种转义序列?

"[^\\]]"

?

诀窍是将']'作为模式中的第一个字符:

scanf(" %80[^]]", &buf);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM