gpt4 book ai didi

c - 使用 fscanf 匹配字段

转载 作者:太空宇宙 更新时间:2023-11-04 04:21:04 24 4
gpt4 key购买 nike

我在 C 程序中解析具有以下格式的文本行:

integer1(字符串)SingleSymbol integer2 integer3 integer4

例如

1001 (abba) S 2000 3000 4000

所以我一个一个地阅读它们,但是我只想提取几个字段,特别是 stringinteger2,我只能想出这个:

fscanf(fp, "%*d (%[^)])", comm)

是否可以在一个 fscanf 表达式中匹配第 4 个字段?

最佳答案

为什么不使用“空格”分隔符将所有参数读取为 string?在你将它们全部读取到一个数组中之后,你可以将你想要的那些转换为 int 等。

关于c - 使用 fscanf 匹配字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46773239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com