C 文件读取问题 急急急 好的加分~~

来源:百度知道 编辑:UC知道 时间:2024/09/27 15:55:15
我现在想读取出bunny_1k.obj文件中的数据。内容为
v 1.2340551 0.255051 0.00482052
v -1.128779 0.302833 0.0741941
……… //有个几十行和上面相同格式的
f 317 187 237
f 187 223 237
………… //也有个几十行
请大侠们帮忙下 将以v f开头的行的数据分别存放进2个二维数组(只存放数字就行了 v f不管) 至少把主要程序写一下 好的加分。~
我写了一点点写不动了 可以参考下。
FILE *fp;
if((fp=fopen("bunny_1k.obj","r"))==NULL)
{
cout<<"cant opEn"<<endl;
exit(0);
}
double f[1000][3] , pos[1000][3]; //数据存放在这里面
//while()
fscanf(fp,"%f %f %f",&f[0][0],&f[0][1],&f[0][2]);
其实意思很简单 就是一个文件,内容为
v 1.2340551 0.255051 0.00482052 //每行都是3个
v -1.128779 0.302833 0.0741941
f 317 187 237
f 187 223 237
读取数据,将v开头的一行三个浮点型数字放进一个二维数组a[][3]中, f开头3个整形数据放入另一个二维数组b[][3]中。

/*程序很简单,也不用多说了*/
#include <stdio.h>
#include <assert.h>
int main(int argc, char* argv[]){
FILE* fp=fopen("bunny_1k.obj","r");
if(fp==NULL) {
printf("cant open file\n");
return 0;
}
double a[1000][3],b[1000][3],x,y,z;
int an=0,bn=0;//an为v的个数, bn为f的个数
for(char vf;fscanf(fp,"%1s %lf %lf %lf",&vf,&x,&y,&z)==4;)
if(vf=='v') {
a[an][0]=x;
a[an][1]=y;
a[an][2]=z;
an++;
} else {
b[bn][0]=x;
b[bn][1]=y;
b[bn][2]=z;
bn++;
}
return 0;
}

不明白什么意识。

不明白什么意思!

读取的我都忘记光了 哎....~~~~~ 帮不上忙了

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

double f[1000][3], pos[1000][3];

void GetLine(char *pString)
{
char szSeps[] = " ,\r\n";
char *token = NULL;
token =