now why would this program only print the first line of the txt file

i put a cout in the constructor and the compiler proved that box was filled with the txt file in the form of an array, now to use it in another function...i only get first four letters :(



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
68
69
70
class alphabet
{
public:

    alphabet()
    {

        ifstream letterfile ("letters.txt.txt");
        for (int q = 0; q<156; q++)
        {
            for (int z = 0; z<6; z++)
            {
                letterfile >> box[q][z];
            }
        }
    }

    void set_arr (int num1,int num2)
    {
        int q=0,z=0;

        for (num1; num1<156; num2++)
        {
            q++;
            for(num2; num2<6; num2++)
            {
                z++;

            }

        }

    }

     void set_box ()
    {
        int q=0,z=0;

        for (q; q<156; q++)
        {

            for(z; z<6; z++)
            {
               cout<<box[q][z];


            }
          cout<<endl;
        }

    }


    char get_arr ( int number1, int number2)
    {
        return arr [number1][number2];
    }
    private:
     char arr [6][6];
    char box [162][6];
};

int main ()
{

    alphabet A;

   A.set_box();

}


EDILT: ignore set arr its part of the function im trying to get working but im not using it here
Last edited on
1
2
3
4
5
for (q; q<9; q++)
        {

            for(z; z<3; z++)
            {
Your not resetting z after the fist loop.
Edit: I changed the array size in testing.
Last edited on
Also, your set_arr function will probably run into issues due to line 22:

for (num1; num1<156; num2++)

I'm pretty sure you should be incrementing num1 here, not num2. :) As it stands, num1 will never change and this creates an infinite loop.
oops! thanks...dumb
Topic archived. No new replies allowed.