bonjour

tout d'abord voici le 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
ifstream ifs(filename);
    int ligne = 0;
    while(!ifs.eof())
    {
        char c = ifs.get();
        if(c == '\n')
        {
            ligne++;
        }
    }
    //cout << "ligne " << ligne << endl;
 
    srand(time(NULL));
    int lignechoisi  = 0;
    while(lignechoisi == 0)
    {
        lignechoisi = rand() % ligne;
    }
    cout << "ligne choisi " << lignechoisi << endl;
 
    ifs.seekg(0, ios::beg);
    int pos = ifs.tellg();
    cout << "position " << pos << endl;
    //lignechoisi--;
    while(lignechoisi > 0)
    {
        //cout << "entrer 2eme boucle" << endl;
        char c = ifs.get();
        cout << c << endl;
        if(c == '\n')
        {
            cout << c << " trouver" << endl;
            lignechoisi--;
            cout << "ligne " << lignechoisi << endl;
        }
    }
alors voila tout marche jusqu'a la deuxieme boucle ou il doit se placer a la ligne choisi il ne lis pas de caratere donc boucle infinie.

donc la question est pourquoi il fait cela ?

ps : je suis presque sur de mon code car deja utiliser une fois pour un jeu de mot mystere qui fonctionne encore