我有一些分析代码 (myprog
),它使用以下方式吸收数据:
if(5 == fscanf(in, "%s%lf%f%f%f", tag, & sec, & tgt, & s1, & s2))
效果很好。但在我有用逗号分隔的数据文件的情况下,我目前正在做类似的事情:
sed 's/,/ /g' data | myprog
我可以修改 fscanf()
函数中的格式字符串以接受两种分隔格式吗?
最佳答案
fscanf(in, "%[^, ]%*[, ]%lf%*[, ]%f%*[, ]%f%*[, ]%f", tag, &sec, &tgt, &s1, &s2)
应该工作吗?
关于c - 如何创建 fscanf 格式字符串来接受空格和逗号 (,) 标记化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2867058/