请问怎么读取文本中的内容为其他格式?
文本内容为:
=================================================
a=3.847,b=3.847,c=12.73
0 0 0 0.375 3 0.98 Tl1
0 1 0 0.375 3 0.98 Tl2
1 0 0 0.375 3 0.98 Tl3
1 1 0 0.375 3 0.98 Tl4
0 0 1 0.375 3 0.98 Tl5
0 1 1 0.375 3 0.98 Tl6
1 0 1 0.375 3 0.98 Tl7
1 1 1 0.375 3 0.98 Tl8
=======================================
我写的C代码是这样的:
=================================================
double a,b,c;
struct superconductor
{
char kind[4];
double px;
double py;
double pz;
double e;
double e_true;
double r;
}sp[100];
fp=fopen(name,"r");
if(fp==NULL)
{
printf("\ninvald name, try again!");
goto input;
}
fscanf(fp,"a=%lf,b=%lf,c=%lf",&a,&b,&c);
number=0;
while( (tmp=feof(fp))==0 )
{
fscanf(fp,"%lf%lf%lf%lf%lf%lf%s",&sp[number].px,&sp[number].py,&sp[number].pz,&sp[number].e,&sp[number].e_true,&sp[number].r,sp[number].kind);
number++;
}
fclose(fp);
===========================
请问这样的代码在CB中应该怎么实现?谢谢!
问题点数:0、回复次数:0Top



