my program do an infinite loop !

my function “lecture” never finish. i don’t understand why. “nb_indices” which at the end of the for loop
is displayed but not the message “hello” which is in the function main.
can you help me please ?
this is the code :

#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
//#include <GL/glut.h>

#define nb_vertices 20000
#define nb_faces 20000

struct donnees
{
float tab_vertices [nb_vertices][3] ;
int tab_sommets [nb_faces][3] ;
};
donnees tab_struct[50] ;
int nb_indices[100] ;

int i=0 ;
int j=0 ;
int k=0 ;
int n=0 ;
int m=0 ;
int l, b ;
int a=0 ;

void lecture ()
{

char tmp [100] ;
char tmp2 [100] ;
char tmp3 [100] ;
int temp [nb_vertices] ;
char passe_ligne [200] ;

char nom_fichier = “bob.ase” ;

FILE *pointeur ; //pointeur sur le fichier

if ((pointeur = fopen(nom_fichier, “r”)) == NULL)
return ;

do
{
fscanf(pointeur, “%s”, tmp) ;
if(strcmp (“*MESH_VERTEX”, tmp) == 0)
{
a++ ;
}
}
while (!feof(pointeur)) ;

fseek (pointeur, 0,SEEK_SET) ;

for (b=1;b<=a;b++)
{

do
{

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

do//rempli le tableau de structure avec des coordonnées de vertices
{

fscanf (pointeur, “%d%f%f%f%s”, &(temp[0]) ,&(tab_struct[b].tab_vertices[i][0]),
&(tab_struct[b].tab_vertices[i][1]),&(tab_struct[b].tab_vertices[i][2]), tmp) ;

cout << tab_struct[b].tab_vertices[i][0]<<" “<<tab_struct[b].tab_vertices[i][1]<<” "<< tab_struct[b].tab_vertices[i][2]<<endl ;
i++ ;

}
while (strcmp (tmp, “}”)!=0) ;

do
{

fscanf(pointeur, “%s”, tmp2) ;
}
while (strcmp (“A:”, tmp2) != 0) ;

do //rempli le tableau de la structure avec le numero des sommets
{

fscanf (pointeur, “%d%s%d%s%d”, &(tab_struct[b].tab_sommets[j][0]),tmp,
&(tab_struct[b].tab_sommets[j][1]),tmp, &(tab_struct[b].tab_sommets[j][2])) ;
//cout << tab_struct[b].tab_sommets[j][0]<<" “<<tab_struct[b].tab_sommets[j][1]<<” "<<tab_struct[b].tab_sommets[j][2]<< endl ;

fgets (passe_ligne, 200, pointeur) ; //saute une ligne dans le fichier où les données ne servent pas
fscanf (pointeur, “%s%s%s”, tmp3, tmp, tmp);
j=j+1 ;
l=l+1 ;
}
while (strcmp(tmp3, “}”)!=0) ;

nb_indices[b] = l*3;
cout << nb_indices[b]<<endl ;
l=0 ;

}

fclose (pointeur) ;
}

void reshape (int w, int h)
{
glViewport (0, 0, w, h) ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity () ;
glFrustum(-100.0 , 100.0, -100.0, 100.0, 5.0, 500.0); //perspective conique
glMatrixMode(GL_MODELVIEW); //la matrice active de modelisation/visualisation sera affectée
glLoadIdentity(); //charge la matrice identité

gluLookAt (0.0, 0.0, 250.0, 0.0,0.0,0.0, 0.0, 1.0, 0.0) ; //caméra placée sur l’axe des Z et regardant vers l’origine
}
void display ()
{

glEnableClientState (GL_VERTEX_ARRAY);

glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) ;

glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT ) ;

for (m=0 ; m<= n ; m++)
{
glVertexPointer (3, GL_FLOAT, 0, &(tab_struct[m].tab_vertices[0][0]));
glDrawElements (GL_TRIANGLES, nb_indices[m], GL_UNSIGNED_INT,&(tab_struct[m].tab_sommets[0][0])) ;
}
glFlush () ;

glutSwapBuffers() ;

}

void main (int argc, char** argv)

{

lecture () ;
cout<<“hello”<<endl ;
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) ;
glutInitWindowSize (640, 480) ;
glutInitWindowPosition (250,250) ;
glutCreateWindow (argv [0]) ;

glEnable( GL_DEPTH_TEST );

glutReshapeFunc (reshape) ;
glutDisplayFunc (display) ;
glutMainLoop () ;

}

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

Add “print a” as the first instruction of the
for loop in order to know if the value of
a is OK and how many time you go through
that loop.

Bye Claude

Post code in code-tags. It’s nearly impossible to follow the code without proper indentation.

i have done a “cout<<a” and it displays me the value : 9035 !!!
how can i do to count my objects if that don’t work ?

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

How about using a debugger to single-step through the program?

Next time you post sourcecode please use the (code) tags just replace the “(” with a “[” and the “)” with a “]”.

Ahhh… But the code tags wont work if you apply them afterwards (because all the tabs have already been deleted in the inital post).

At first sight I can tell that you have too many blocks while(expression);
If you put semicolon after while, your loop will never execute… or worse - it will executing nothing but will executing it until the expression is true - there are no code executing, which change expression
First, remove all ; that are immediately after while
Hope this will be helpfull

Those are do-while loops, and the semi-colon does follow the while’s for those.