gpt4 book ai didi

linux - 将数据转换为不同格式的简单工具

转载 作者:太空宇宙 更新时间:2023-11-04 05:31:10 25 4
gpt4 key购买 nike

我正在自学统计学和编程。什么样的 C 或 Python 程序可以解决 Linux 中的以下问题?

我有一个以下形式的文本(可能是 CSV)文件

pcb138  pcb180  pcb52   pcb118  pcb
1,46 ,738 ,532 ,72 19,9959
,64 ,664 ,03 ,236 6,0996
3,29 1,15 ,134 1,54 24,9655
3,94 1,33 ,466 1,94 37,4436
...
32,3 31,5 1,8 8,49 318,7461

现在我想将它们转换为另一个程序可以理解的另一种格式。即,表单的文本文件

pcb138=[1.46,0.64,3.94,...,32.3]
pcb180=[0.738,0.664, 1.15,1.33,...,31.5]
pbc52=[0.532, 0.03, 0.134, 0.466, ...,1.8]
pbc118=[0.72, 0.236, 0.154, 1.94, ...,8.49]
pbc=[19.9959, 6.0996, 24.9655, 37.4436, ...,318.7461]

最佳答案

使用二维数组和 strtok() 编写 C 程序来进行解析 http://www.cplusplus.com/reference/cstring/strtok/

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}

关于linux - 将数据转换为不同格式的简单工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18113704/

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