请教高手,我现在有多段数据。打算用C语言提取有用信息。
NAME: |SC301|CN1|MP1-MODN:105(%100.0)|AM5484|PC47|SN27|WD1.2|TA2.6|TR1138.3|FR299-302|RT4.9961|MN0.091|RA0.0739|IS67280|MO20: 105 120 53 54 81 57 106 52 80 67 68 66 77 79 58 65 78 82 91 103|EW0-6|FG0.845|TN7.649|OR2|NT0
RE
0 41949 12647 12685
NUM PEAKS: 73
(51,156 )(52,253 )(53,560 )(54,389 )(55,587 )
(57,328 )(58,198 )(63,83 )(64,67 )(65,215 )
(66,233 )(67,277 )(68,267 )(70,143 )(71,93 )
(76,84 )(77,231 )(78,169 )(79,216 )(80,229 )
(81,336 )(82,158 )(90,36 )(91,152 )(103,143 )
(104,81 )(105,999 )(106,269 )(120,618 )(121,70 )
这是其中一段数据,其中只有括号中的是要处理的,要把逗号前后的数据分别提取出来,放在二维数组中。每段数据都是同样的存储格式,但是存储数据不同.如何能把这多段数据提取出来?
愁愁!请教高手!若能附源码,不胜感激!
程序:
C
#include <stdio.h>
#define N 64
int main(){
int array[N][2];
int a,b,i=0;
char ch;
FILE *fp;
fp=fopen("c://data1.txt", "r");
if(fp==NULL)
return 1;
while(ch=fgetc(fp)){
if(ch==EOF) break;
if(ch!='(') continue;
if(fscanf(fp,"%d,%d", &a,&b)==2){
array[i][0]= a;
array[i++][1]= b;
}
}
// print the array:
for(a=0;a<i;a++)
printf("%4d %4d/n", array[a][0], array[a][1]);
return 0;
}
C++
#include <iostream>
#include <fstream>
using namespace std;
struct Data
{
char a;
int b;
char c;
int d;
char e;
};
int main()
{
ifstream in("1.txt");
ofstream out("2.txt");
Data data;
while(!in.eof())
{
in>>data.a>>data.b>>data.c>>data.d>>data.e;
out < <data.b < <"/t" < <data.d < <endl;
}
return 0;
}