![](/img/trans.png)
[英]How to read and store 2 float values seperated by a comma from a file into two arrays where each float is stored in one array
[英]C - Read lines from file with float seperated by comma
假设我有一个用逗号分隔的浮点文件,如下所示:
-5.5753,7.8474,4.1311
-6.4047,10.7159,4.8474
7.4603,-8.5214,-8.0286
10.5086,-6.1559,-7.0605
...
而且我以前不知道每行中有多少个浮点数。 有没有一种好方法可以一个接一个地阅读它们?
我试过类似的东西:
fscanf(data, "%lf", &num);
但它只能读取第一个数字。
谢谢!
您需要每行扫描 3 个数字。,
if (fscanf(data, "%lf,%lf,%lf", &num1, &num2, &num3) != 3) { /* handle error */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.