Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

juglarx

Problem whit sfcanf and huge file

This topic is 5855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people! i have a problem whit a huge file in txt format , i try to read this TXT very long file and i use fscanf , but i only can read 900 elements of this file , anyone have a trick or something to read a big txt file? here is the code i use /*************************************/ FILE * fp; float *vertex = new float; int *faces = new int; fp=fopen(name, "r"); setbuf(fp, buf ); fscanf(fp,"%d",&num_vtx); printf("num vtx = %d\n",num_vtx); printf("start loading vtxs\n"); for(int i=0;i<(num_vtx*3);i++){//24 printf("%d ",i); fscanf(fp,"%f",&vertex); } fscanf(fp,"%d",&num_faces); printf("\nnum faces:%d\n",num_faces); printf("start loading faces\n"); for(int j=0;j<(num_faces*3);j++){//12 printf("%d ",j); fscanf(fp,"%d",&faces[j]); }

Share this post


Link to post
Share on other sites
Advertisement

  

typedef struct {float x,y,z;} tVertex;
tVertex *_Vertexes = NULL;

BOOL readVtx ( const char *filename )
{
FILE *fhd = NULL;

if ( ( fhd = fopen (filename, "rt" ) ) == NULL )
return FALSE;

fscanf ( fhd, "%d",&_numVtx );
printf ( "Number of vertexes : %d\n", _numVtx );

_Vertexes = malloc ( sizeof (tVertex)*_numVtx );

for ( int i = 0; i < (_numVtx); i++ )
fscanf ( fhd, "%f %f %f", &_Vertex[i].x, &_Vertexes[i].y, &_Vertexes[i].z );

fclose ( fhd );
return ( TRUE );
}


Should work, add some validation. And the vertex file should be in format:


x y z
x y z
...

ie:

2
1.0 1.0 1.0
2.0 2.0 2.0


And remember to free allocated memory. This was written on top of my head, but I think you get the picture.

Share this post


Link to post
Share on other sites
First, why are you using setbuf? And if you do, you should be using setvbuf, because setbuf in antiquated.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!