PDA

View Full Version : [to make an open gl program]how come back at the beginning of a file ?



airseb
01-03-2003, 07:16 AM
i have made a program which read in an ase file, and each part before and after the "fseek" works separatly. But the problem is that the second part (after the fseek)is not executed and i don't understand why.
can you help me please ? i haven't found any help in others places.

#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>


#define nb_vertices 200000
#define nb_faces 200000

float tab_vertices [nb_vertices][3] ;
int tab_sommets [nb_faces][3] ;

void lecture ()
{

char tmp [100] ;
char tmp2 [100] ;
int temp [nb_vertices] ;
char chaine [100] ;
char chaine2 [100] ;
strcpy (chaine , "*MESH_VERTEX") ;
strcpy (chaine2 , "*MESH_FACE") ;

int i=0 ;
int k=0;
char nom_fichier[] = "cool.ase" ;


FILE *cool ; //pointeur sur le fichier cool

if ((cool = fopen(nom_fichier, "r")) == NULL)
return ;


do
{
do
{

fscanf(cool, "%s", tmp) ;
}
while (strcmp (chaine, tmp) != 0) ; //passe toutes les chaines en revue qu'a ce que tmp soit égal à chaine ("*MESH_VERTEX")


do//fill the array with the array of vertices
{

fscanf (cool, "%d%f%f%f%s", &(temp[0]) , &(tab_vertices[i][0]), &(tab_vertices[i][1]),
&(tab_vertices[i][2]), tmp) ;
//cout << tab_vertices[i][0]<<" "<< tab_vertices[i][1]<<" "<< tab_vertices[i][2]<<endl ;
i=i+1 ;

}
while (strcmp (tmp, "}")!=0) ;

}
while (!feof(cool)) ;

fseek (cool, 0, SEEK_SET) ;

do
{

do //fill the array with the numbers of indices
{
do
{

fscanf(cool, "%s", tmp2) ;
}
while (strcmp (chaine2, tmp2) != 0) ;



fscanf (cool, "%s %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d",
tmp, tmp, &(tab_sommets [k][0]),tmp,&(tab_sommets [k][1]),tmp, &(tab_sommets [k][2]), tmp,
&(temp[0]),tmp, &(temp[0]),tmp, &(temp[0]),tmp, &(temp[0]),tmp, &(temp[0])) ;

cout << tab_sommets [k][0]<<" "<<tab_sommets [k][1]<<" "<<tab_sommets [k][2] << endl ;
k=k+1 ;

}
while (strcmp (tmp2, "}")!=0);
}
while (!feof(cool)) ;


fclose (cool) ;

}

void main ()

{

lecture () ;
getch ();
}


[This message has been edited by airseb (edited 01-03-2003).]

[This message has been edited by airseb (edited 01-03-2003).]

Claude
01-03-2003, 03:31 PM
First you check for "*MESH_VERTEX".

Then you read the vertices.

Then you check for EOF. Since it's not the end of the file,you check for "*MESH_VERTEX"
again. Might that be a infinite loop ?

Hope it helps. Claude.