Bonjour,

J'ai un problème avec une fonction qui récupère des données sur un socket et qui fait une boucle. Tout marche parfaitement quand il y a std::cout (ou printf) dans la boucle mais ça plante une fois sur 2 quand il n'y est pas :s. Je n'ai pourtant aucun warning. Qu'est ce qui peut déclencher ceci ? Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
using namespace std;
#define order 8
void printall(int arr[]);
bool validity_check(int,int,int []);
int main()
{
        int nextjump[order];//Keeps track for every order what should be the pos. of next jump.
        for(int i=0;i<order;i++) nextjump[i]=0;
        int level=0;
        int position[order];
        mainloop:
        while(true)
        {
                //cout<<"Entered the while loop"<<endl; //This is the line which can change the whole output when uncommented
                for(int i=nextjump[level];i<order;i++)
                {
                        if(validity_check(level,i,position))
                        {
                                cout<<"Successful at level "<<level<<" using position "<<i<<endl;
                                position[level]=i;
                                nextjump[level++]=i+1;


                                if(level==order)
                                {

                                        printall(position);
                                        goto mainloop;
                                }

                                nextjump[level]=0;
                                goto mainloop;
                        }
                }

                level-- ;
                goto mainloop;
        }
        return 0;
}

bool validity_check(int level,int n, int current[])
{
        for(int i=0;i<level;i++)
        {
                if(current[i]==n) return false;
        }
        //Level 0 has always full validity.
        if((level>0)&&(level<order-1))
        {
                if((current[level-1]==n)|(current[level+1]==n)) return false;
        }
        if(level==order-1)
        {
                if(current[level-1]==n) return false;
        }

}

void printall(int current[])
{
        for(int i=0;i<order;i++)
        {
                cout<<current[i]<<endl;
        }
}
Merci