哎呀,这在c中是什么意思?

发布于 2024-11-08 12:47:38 字数 125 浏览 0 评论 0原文

if ( sscanf( line, "%[^ ] %[^ ] %[^ ]", method, url, protocol ) != 3 )...

上面那个格式很奇怪,它是做什么用的?

if ( sscanf( line, "%[^ ] %[^ ] %[^ ]", method, url, protocol ) != 3 )...

That format above is very strange,what's it doing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只有影子陪我不离不弃 2024-11-15 12:47:38

该行尝试将 3 个不包含空格分隔的字符串读取到 method、url、protocol 中,如果无法读取 3 个字符串,则会进入 if 块。

That line is attempting to read 3 strings that do not contain a space separated by spaces into method, url, protocol and if it fails to read 3 it will then enter the if block.

恍梦境° 2024-11-15 12:47:38

[] 是扫描集。如果您告诉 %[abcd],则输入字符串仅包含 abcd 将被考虑。该字符串将在第一次出现某个其他字符时终止,该字符不是大括号中的任何字符。

[] 内的 ^ 用于表示大括号内集合的补集。与格式字符串 %[^abcd] 一样,仅接受所有字符 除了ab 或 < em>c 或 d

因此,在 %[^ ] 中,^ 后面的空格表明,格式字符串将接受字符串中的任何字符组合,其中 < em>没有有空格。

格式字符串 "%[^ ] %[^ ] %[^ ]" 将匹配具有由空格分隔的三个组成部分的字符串。每个组件将包含一个字符序列,其中没有空格。

该函数返回成功匹配和分配的输入项的数量,该数量可能少于提供的数量,如果早期匹配失败,甚至为零。

因此,仅当且仅当读取了所有三个组件时,上述函数才会返回 3,即输入行具有三个分区,并且对于每个分区,三个数组方法urlprotocol 已填充。

the [] is the scanset. If you tell %[abcd] then an input string only with a or b or c or d will be considered. The string would terminate at the first occurance of some other character which is not any of the characters in the braces.

The ^ inside the [] is used to denote the compliment of the set inside the braces. Like with the format string %[^abcd] will only accept all characters except , a or b or c or d.

so in %[^ ] , the blankspace followed by the ^ tells that, the format string will accept any character combination in the string which does not have a blankspace.

The format string "%[^ ] %[^ ] %[^ ]" will match a string which has three components separated by blankspaces. Each of the component will contain a sequence of characters which have no space inside them.

The function returns the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.

So the above function will return 3 only if and only if all the three components are read, that is, the input line has three partitions and for each partition the three arrays method, url and protocol was populated.

怀念你的温柔 2024-11-15 12:47:38

scanf 是一个从字符串中读取数据并返回项目数的函数成功读取。

因此,scanf将解析line以找到3个包含空格并以空格分隔的字符串,并将这3个字符串放入后面的3个变量中(方法url协议)。

然后,如果它解析了 3 个参数,它将进入 if 块。

scanf is a function that reads data from a string and returns the number of items successfully read.

So, scanf will parse line to to find 3 string containing a space and separated by a space and will put these 3 strings in the 3 variables that follows (method, url, protocol).

Then if it has parsed 3 arguments, it'll enter the if block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文