-1

我正在自学统计和编程。什么样的 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]
4

1 回答 1

0

使用二维数组和 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;
}
于 2013-08-07T21:11:45.997 回答